Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6638393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:25:50+00:00 2026-05-25T23:25:50+00:00

I have a simple MS Access form that has 3 objects: a text box,

  • 0

I have a simple MS Access form that has 3 objects: a text box, a list box, and a button. The intended use of the form is as follows: the user enters a name in the text box, selects an item from the list box, then clicks the button to add the data to a table.

However, when I click on the button, I keep getting the error message, “You can’t reference property or a method for a control unless the control has the focus.”

Below is my code. Thanks!

Private Sub addRecord_button_Click()
    Dim CustomerName As String
    Dim CustomerType As String

    On Error GoTo Errhandler

    CustomerName = "[name not selected]"
    CustomerType = "[type not selected]"

    CustomerName = Customer_TextBox.Text

    Select Case Type_ListBox.ListIndex
        Case 0
            CustomerType = "Type 1"
        Case 1
            CustomerType = "Type 2"
        Case 2
            CustomerType = "Type 3"
    End Select

    'MsgBox ("Name: " & CustomerName & " and Type: " & CustomerType)

    DoCmd.RunSQL "INSERT INTO Customer VALUES (CustomerName, CustomerType);"

Errhandler:
    MsgBox ("The following error has occured: " & Err & " - " & Error(Err))
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T23:25:50+00:00Added an answer on May 25, 2026 at 11:25 pm

    The .Text property can only be used when the TextBox has focus. Try using the .Value property instead.

    Try replacing the below line

    CustomerName = Customer_TextBox.Text
    

    with

    CustomerName = Customer_TextBox.Value
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple login form that has 2 text fields and a button.
So I have a form that I want the user to use to update
I'm trying to use NHibernate for data access, and I have 2 simple entities
I have a very simple sinatra site that I'm trying to access via ajax
I have a very simple DLL written in unmanaged C++ that I access from
I have a very very simple SQL string that MS Access doesn't seem to
I'm writing a simple web app in PHP that needs to have write access
Story I have a select control that represents user access level. I'm looking for
I have a simple form showing products from my database. Each product has a
I have a fairly large CRUD WinForm app that has numerous objects. Person, Enrollment,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.