Results 1 to 8 of 8
  1. #1
    vavs is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    4

    Lookup using second recordset

    I am new to VBA and Access but I am getting through my first program.



    I have reached a part where I need some help. I have a recordset that looks at a table in my database. I am using Access 2007. I am checking a field called Gauge that is a text field. I am checking for different characteristics and then populating three fields with the appropriate values. I am stuck because there is a case where the field contains a character string that will require me to lookup the information in another table. If I see the characters GA in my Gauge field, I need to find the values for that identifier in another table called tblGauge. To make matters worse, I need it to look up another field in the original table to find the right value. I am using a Do While loop to go through all of the records and update. I am attaching the code to this post for reference. The highlighted line is where I need the help. I put a select statement together that describes what I am looking to get out of the system.

    If I need to provide any other information feel free to let me know. I am new to Access so please be specific in your requests.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Replace the SELECT statement with a DLookup(). You can't just have SQL like that. You could also open a recordset on that SQL and get the value that way.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    vavs is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    4
    I was just using the sql to describe what I was hoping to return.

    I set up the dlookup but I am not getting results.

    My recordset is linked to a table tblTMIINV. My table that contains the results is tblGauge. Here is my dlookup statement:

    DecIn = Dlookup(tblGauge.Low, tblGauge, .Fields("Gauge") = tblGauge.Gauge And .Fields("Grade") = tblGauge.Grade)

    Do I need to set up tblGauge as another recordset? If I do then how do I do that inside of a do while loop?

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Here's a good reference on the required syntax:

    DLookup Usage Samples

    Use the form control method, replacing the form reference with your recordset reference.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    vavs is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    4
    Paul,

    Here is my code:
    */ If InStr(.Fields("Gauge"), "GA") Then

    DecIn = DLookup("Low", "tblGauge", "Gauge = " & .Fields("Gauge") & " AND Grade =" & .Fields("Type"))

    /*
    The .Fields("Gauge") references back to the records set associated with tblTMIINV. I am calling the tblGauge in the DLookup. When I run the code, I get an error message 3075 Syntax error (missing operator) in query expression 'Gauge = 24 GA AND Grade = CT'. I am guessing that since both of those are text fields I have to get the single quotes in somehow.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Your guess is correct. Try:

    DecIn = DLookup("Low", "tblGauge", "Gauge = '" & .Fields("Gauge") & "' AND Grade ='" & .Fields("Type") & "'")
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    vavs is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    4
    Thanks for all your help. This will save my company hours of time for processing of the data as well as thousands of dollars in licensing costs. With this I can convert my ERP database to a useable format and reduce the number of licenses.

    Now I just need to spend 2- 3 days in programming all of the forms and reports.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Happy to help, and welcome to the site by the way.
    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. Recordset Search
    By ColPat in forum Programming
    Replies: 2
    Last Post: 08-14-2010, 08:25 PM
  2. ADO Recordset.Open (SQL) does nothing
    By workindan in forum Programming
    Replies: 3
    Last Post: 06-23-2010, 02:07 PM
  3. this recordset is not updateable
    By astraxan in forum Queries
    Replies: 6
    Last Post: 05-24-2010, 02:06 PM
  4. Replies: 1
    Last Post: 11-13-2009, 03:03 AM
  5. The Recordset is not updatable
    By bullet_proof302 in forum Access
    Replies: 2
    Last Post: 11-07-2009, 12:13 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