Results 1 to 10 of 10
  1. #1
    jker is offline Advanced Beginner
    Windows 10 Access 2007
    Join Date
    Aug 2023
    Posts
    36

    Access forms 2007- have a value from combox be passed to do a query

    i have a SALES form.

    in that form i have a combox box (CbxSelectCustomer) . user selects from the combo box which is based on CUSTOMER table.



    I then want an event to do a sql query of my CUSTOMER table to find the record by matching the value selected from combo box to [customer.CUST_CONCAT_LONG] in my CUSTOMER table.

    Then based on that result of the SQL, i want to populate a textbox (TEXT188 FFNAME) on my form from [customer.fname]

    Private Sub CbxSelectCustomer_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

    Me!Text188 = Me!CbxSelectCustomer.Column(1)

    End Sub

  2. #2
    jker is offline Advanced Beginner
    Windows 10 Access 2007
    Join Date
    Aug 2023
    Posts
    36

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,574
    Just bring that data in as extra columns of your combo
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    xps35's Avatar
    xps35 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jun 2022
    Location
    Schiedam, NL
    Posts
    300
    No need for an extra query. Make sure you select the first name in the query that is the source for the combo:
    Code:
    select CUST_CONCAT_LONG, fname from customer
    Then make a after update event on the combo:
    Code:
    me.[TEXT188 FFNAME] = me.CbxSelectCustomer.Column(1)
    Note that Column(1) is the second column!
    Groeten,

    Peter

  5. #5
    jker is offline Advanced Beginner
    Windows 10 Access 2007
    Join Date
    Aug 2023
    Posts
    36
    Quote Originally Posted by xps35 View Post
    No need for an extra query. Make sure you select the first name in the query that is the source for the combo:
    Code:
    select CUST_CONCAT_LONG, fname from customer
    Then make a after update event on the combo:
    Code:
    me.[TEXT188 FFNAME] = me.CbxSelectCustomer.Column(1)
    Note that Column(1) is the second column!

    *************************************
    i made an AFTER UPDATE event for the combo box as you said, and i created a new test box with CONTROL SOURCE of FFNAME


    what i dont understand is where to include the 'SELECT' statement you are referring to. Can you please explain. I am very new to access so I have a lot of questions.

  6. #6
    xps35's Avatar
    xps35 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jun 2022
    Location
    Schiedam, NL
    Posts
    300
    You do not need an extra text box with a control source. The text box (text188) will get a value in the event.
    The sql is the rowsource of combobox. Make sure to set the ColumnCount property to 2.
    Groeten,

    Peter

  7. #7
    jker is offline Advanced Beginner
    Windows 10 Access 2007
    Join Date
    Aug 2023
    Posts
    36
    hello,
    I found the solution with your help.
    1- changed my SELECT statement for the combo box to include all the fields i wanted

    2- create a textbox for each field and mapped them in my EVENT. see code below



    Private Sub CbxCustomerSelect_AfterUpdate()
    Me.[Text202] = Me.CbxCustomerSelect.Column(0) 'customer number
    Me.[Text194] = Me.CbxCustomerSelect.Column(3) 'first name
    Me.[Text196] = Me.CbxCustomerSelect.Column(2) 'last name
    Me.[Text198] = Me.CbxCustomerSelect.Column(4) 'house number
    Me.[Text200] = Me.CbxCustomerSelect.Column(5) 'street
    Me.[Text204] = Me.CbxCustomerSelect.Column(6) 'apartment
    Me.[Text206] = Me.CbxCustomerSelect.Column(7) 'city
    Me.[Text208] = Me.CbxCustomerSelect.Column(8) 'state
    Me.[Text210] = Me.CbxCustomerSelect.Column(9) 'zipcode
    Me.[Text212] = Me.CbxCustomerSelect.Column(10) 'country

  8. #8
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,823
    Why are you doing this?

    If you have a Form based on the Sales Table all you need is a Combobox to select a specific Customer.
    All of the additional fields do not need to be displayed.

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,574
    Do your self a HUGE favour right now.

    Give your controls meaningful names. Text202 and whatever other generic name, is going to mean absolutlely nothing to you a few days down the road, nor to any poor sod who has to take it over from you.

    Quote Originally Posted by jker View Post
    hello,
    I found the solution with your help.
    1- changed my SELECT statement for the combo box to include all the fields i wanted

    2- create a textbox for each field and mapped them in my EVENT. see code below



    Private Sub CbxCustomerSelect_AfterUpdate()
    Me.[Text202] = Me.CbxCustomerSelect.Column(0) 'customer number
    Me.[Text194] = Me.CbxCustomerSelect.Column(3) 'first name
    Me.[Text196] = Me.CbxCustomerSelect.Column(2) 'last name
    Me.[Text198] = Me.CbxCustomerSelect.Column(4) 'house number
    Me.[Text200] = Me.CbxCustomerSelect.Column(5) 'street
    Me.[Text204] = Me.CbxCustomerSelect.Column(6) 'apartment
    Me.[Text206] = Me.CbxCustomerSelect.Column(7) 'city
    Me.[Text208] = Me.CbxCustomerSelect.Column(8) 'state
    Me.[Text210] = Me.CbxCustomerSelect.Column(9) 'zipcode
    Me.[Text212] = Me.CbxCustomerSelect.Column(10) 'country
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  10. #10
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,425
    Then based on that result of the SQL, i want to populate a textbox
    Your approach might be OK for one textbox but not for several. It makes no sense to do it that way. You create the query that returns the results you want (based on criteria if required). Your form uses that query for its recordsource and you bind (link) a control on the form for each field in the query. So 8 query fields, 8 controls. They don't all have to be textboxes. In fact, you can use a form wizard and get a basic form in seconds, using that query. I don't advocate that you leave the automated design the way it turns out, but that's another story.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Forms, Combox Edit List Option
    By RoundTrip in forum Access
    Replies: 7
    Last Post: 03-02-2014, 09:13 PM
  2. Replies: 3
    Last Post: 10-31-2013, 02:36 PM
  3. Access 2007 db forms not working in Access 2010
    By Butterfly13 in forum Access
    Replies: 2
    Last Post: 09-07-2012, 12:45 PM
  4. Replies: 2
    Last Post: 06-18-2011, 09:55 AM
  5. Access 2007 Filtering Forms
    By mab in forum Forms
    Replies: 2
    Last Post: 05-20-2011, 06:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums