Results 1 to 9 of 9
  1. #1
    rtcary is offline Advanced Beginner
    Windows XP Access 2002 (version 10.0)
    Join Date
    May 2010
    Posts
    35

    How to have a form field based on a query?

    I have a combo box on a form that gives the user an opportunity to select an Ad type with the primary key stored. Now I want to have an unbound field that uses a query based on the saved key to populate another field. When I right click on the unbound field, I do not see an option to use a query. No doubt I'm missing something.

    Todd

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    You can have the combo AFTER UPDATE event run a DLOOKUP to populate the unbound box

    txtBox = Dlookup("[field]","[table]", "[lookupKey]=" & me.comboBox)

    (its a lot more programming to do a right-click)

  3. #3
    rtcary is offline Advanced Beginner
    Windows XP Access 2002 (version 10.0)
    Join Date
    May 2010
    Posts
    35
    I'll give that a try though the DLookup syntax will take some trial and error.

    What I meant by my reference to right-click is when I was trying to find properties or methods for the unbound field while in design mode, I did not find a way to use a query for obtaining the contents for the unbound field.

    Thank you,

    Todd

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    You normally dont. Fields should be bound on the form.
    But if you want and unbound to fill in data from the combo, I pull the info from the combo box query. I give it extra fields in the query, tho the user cant see them. col.width = 0
    Then when the user picks an item in the combo, the AFTERUPDATE event just copies the data over. Its faster than DLOOKUP.

    afterupdate()
    txtBox = cboBox.column(1)

  5. #5
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    For clarity:


    Tables have fields.
    Tables store data.
    Forms/controls do not store data. Forms/controls are a method to view data.

    Forms may or may not have a record source. A bound form has a record source, either a table, a saved query or a SQL string. An unbound form does not have a record source.

    Forms have controls. A control can be bound or unbound. A bound control has a control source - a field in the record source of the form. An unbound control typically does not have a control source. But an unbound control can have an expression in the control source.


    There is no such thing as an "unbound field".

  6. #6
    rtcary is offline Advanced Beginner
    Windows XP Access 2002 (version 10.0)
    Join Date
    May 2010
    Posts
    35
    OK! This works:
    Private Sub Combo18_AfterUpdate()
    Text20 = Combo18.Column(2)
    End Sub

    However, the value (column(1) ) no longer shows in the combo field *after* update. I assume that needs to be added to the above. If so, what is the syntax?

    Many thanks...

    Note: I added BoundColumn = 1. That seemed to fix it. Apparently, I guessed correctly at the syntax.

    Todd

  7. #7
    rtcary is offline Advanced Beginner
    Windows XP Access 2002 (version 10.0)
    Join Date
    May 2010
    Posts
    35
    Thank you. Learning the Access nomenclature is taking time coming from Delphi.

    Todd

  8. #8
    rtcary is offline Advanced Beginner
    Windows XP Access 2002 (version 10.0)
    Join Date
    May 2010
    Posts
    35
    Many thanks for the help as I dive into Access. Using the following, it works:

    Private Sub Combo18_AfterUpdate()
    BoundColumn = 1
    Text20 = Combo18.Column(2)
    End Sub

    I have a minor question:

    * I cannot find how to change an Objects name e.g. Text20 to AdAmount.

    Again, thank you...

    Todd

  9. #9
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Learning the Access nomenclature is taking time coming from Delphi.
    dBaseIII, dBaseIV and Turbo Pascal for me.......


    * I cannot find how to change an Objects name e.g. Text20 to AdAmount.
    In design view, dbl click on the control to open the properties dialog box.
    Click on the other tab.
    The top property is "Name".....

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

Similar Threads

  1. Query to look up value based on form field
    By c.stewart28 in forum Access
    Replies: 1
    Last Post: 04-24-2015, 09:19 AM
  2. Replies: 3
    Last Post: 11-26-2014, 06:05 PM
  3. Replies: 1
    Last Post: 08-04-2011, 04:17 PM
  4. Replies: 4
    Last Post: 07-28-2010, 10:27 AM
  5. Replies: 1
    Last Post: 11-10-2009, 03:20 PM

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