Results 1 to 4 of 4
  1. #1
    Mike106 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2012
    Posts
    2

    Lookup question

    I have a form with fields bound to table1. Field1 is a combo list that is populated by values from field1 in table2. Tsble2 has other fields that correspond to fields in table1. When I am adding a new record in talbe1 and select a choice in the field1 combo list that would have the same value in field1 in table2, I would like to have the corresponding values from the corresponding table2 fields to appear in the form but not necessarily accepting the values before I commit the record to the table. How do I accomplish this? I am new to VBA.

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Mike106 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2012
    Posts
    2
    Quote Originally Posted by pbaldy View Post
    No, I couldn't get it to work. What I would like to do is have VBA code that does the following:
    After the selection is made from the combo box "Entry Title" the following query runs:
    SELECT Commons.Checks, Commons.ACCTNUM, Commons.Amount, Categories.Description, Categories.[Income/Expense]
    FROM Categories RIGHT JOIN Commons ON Categories.ID = Commons.CATEGORY
    The query would have a where clause, where Common.Checks= the value in the combo box "Entry Title". The values returned from the query would be entered in the corresponding fields in the form.

    I am migrating an app that I developed in Paradox years ago to Access 2010. I am using the "Personal account ledger" template. I made a few adaptions, imported all my data. It works fine, but don't know VBA to automate common tasks.

    This is the Paradox code that I used in the Paradox app on the combo box Entry Title.
    method depart(var eventInfo MoveEvent)
    Var
    tc TCursor
    s String
    EndVar
    s = CHECKNAME.value
    If isedit() Then
    If AMNT = 0 Then
    tc.open(":mikedb:commons.db")
    If tc.locate("Checks", s)

    Then
    AMNT.value = tc.("Amount")
    NOTES.value = tc.("ACCTNUM")
    EXPCAT.value = tc.("CATEGORY")
    EndIf
    EndIf
    EndIf
    endMethod

    s is the value in the combo box. A tCursor is method that points to a record in a table without running a query. If the equivalent of a tCursor doesn't exist in VBA, then the values returned from the query I described above would work.
    Thanks

  4. #4
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    The linked method is the most efficient, but see if this gets you started:

    Code:
      Dim strSQL        As String
      Dim rslookup      As DAO.Recordset
    
        strSQL = "SELECT ResNum, AuthBy, PassName " & _
                 "FROM tblReservations " & _
                 "WHERE Resnum = " & Me.Reservation_num
    
        Set rslookup = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset, dbSeeChanges)
    
        If Not (rslookup.EOF) Then
          'no records found
        Else
          'record(s) found
        End If
    
        Set rslookup = Nothing
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Lookup Question
    By Lookup in forum Import/Export Data
    Replies: 11
    Last Post: 11-12-2012, 08:31 PM
  2. Replies: 5
    Last Post: 09-21-2012, 11:23 AM
  3. Lookup Question
    By uaguy3005 in forum Access
    Replies: 1
    Last Post: 05-22-2012, 03:02 PM
  4. Table Lookup Question
    By Atlascycle in forum Access
    Replies: 2
    Last Post: 02-21-2012, 03:28 PM
  5. Lookup Wizard Question
    By Marisha in forum Access
    Replies: 6
    Last Post: 10-27-2011, 12:54 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