Results 1 to 8 of 8
  1. #1
    cvegas is offline Novice
    Windows XP Access 2000
    Join Date
    Apr 2011
    Location
    Boulder City, NV
    Posts
    13

    Simple Syntax Help

    Have txtbox where user enters vendor invoice number

    I want to go into my table dbo_AccountsPayable and see if there is a record where [InvoiceNumber] = the data in the txtbox

    If found then I need to open a form and display the data from that record.
    docmd openform "Found"

    If not found I need to open a different form and insert a new record into the table.
    docmd openform "NotFound"

    I know it's basic but I am having a DUGH moment

    Thanks in advance for any help

  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,640
    You can use a DCount() to test for existing records, and open the appropriate form. More info on syntax:

    DLookup Usage Samples
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    cvegas is offline Novice
    Windows XP Access 2000
    Join Date
    Apr 2011
    Location
    Boulder City, NV
    Posts
    13
    Thank you for your reply.

    Could use help with how to determine if the Dlookup found the record or not?

    if Dlookup = true then load form1 else load form2

  4. #4
    cvegas is offline Novice
    Windows XP Access 2000
    Join Date
    Apr 2011
    Location
    Boulder City, NV
    Posts
    13
    The textbox on my form where this data would be entered is Named "FindInvoiceFromVendorPage"

    Not sure what Criteria is referring to? Is this the Field name?
    How do I pass the value in that field to the lookup?

    Dlookup("InvoiceNumber","dbo_AccountsPayable","Fin dInvoiceFromVendorPage="""

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Again, I would use DCount, not DLookup (though you can use DLookup by testing for Null):

    If DCount(...) > 0 Then

    would indicate a record existed. The criteria syntax is basically:

    FieldName = Value

    so in your case

    DCount("*","dbo_AccountsPayable","[InvoiceNumber] = " & Me.FindInvoiceFromVendorPage)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    cvegas is offline Novice
    Windows XP Access 2000
    Join Date
    Apr 2011
    Location
    Boulder City, NV
    Posts
    13
    Sorry I replied to the message I got in my inbox instead of here
    I created a new textbox on the form called "FindInvoice" to test this.
    I pasted your syntax in and got the "Expected = error"
    I tried several variations to see if I could figure it out but had no luck

    FYI the actual field I need to search in the table is named "VendorInvoiceNum" so I subsisted that in your syntax.
    Below is a screen shot of my attempts.
    I know this should not be this hard but again DUGH!
    Hope this one resolves this. Thanks again

  7. #7
    cvegas is offline Novice
    Windows XP Access 2000
    Join Date
    Apr 2011
    Location
    Boulder City, NV
    Posts
    13
    Sorry last message was to long to post screen shot

    Private Sub FindInvoice_AfterUpdate()
    DLookUp("VendorInvoiceNum","dbo_tblAccountsPayable ","[VendorInvoiceNum]= & FindInvoice")
    'DCount("*","dbo_AccountsPayable","[InvoiceNumber] = " & FindInvoiceFromVendorPage)
    'The above was sent in email and pasted in here but does not work (says Expected =)
    'Below are my attempts to change the syntax which do not work
    DCount("*","dbo_AccountsPayable","[VendorInvoiceNum] = ' & FindInvoice")
    DCount("*","dbo_AccountsPayable","[VendorInvoiceNum] = & FindInvoice")
    End Sub


  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,640
    Well, you can't just have the DCount alone like that. You either set a variable to its value:

    VariableName = DCount(...)

    or test it like my example:

    If DCount(...) > 0 Then

    When you have it alone like that, Access doesn't know what you want done with it.
    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. Help with syntax
    By GWB in forum Queries
    Replies: 4
    Last Post: 01-26-2011, 03:33 PM
  2. Replies: 0
    Last Post: 10-21-2010, 08:24 AM
  3. simple syntax question
    By markjkubicki in forum Programming
    Replies: 6
    Last Post: 09-14-2010, 04:13 PM
  4. Incomplete Syntax Clause (syntax error)
    By ajetrumpet in forum Programming
    Replies: 4
    Last Post: 09-11-2010, 10:47 AM
  5. Simple Export Not So Simple
    By jgelpi16 in forum Programming
    Replies: 11
    Last Post: 09-01-2010, 07:23 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