Results 1 to 4 of 4
  1. #1
    TamworthBob is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    May 2020
    Posts
    21

    USe the WITH STATEMENT

    Here is my code:
    With tblCustomerPartNumbers
    ' Use three conditions with AND
    .FindFirst "[StationID]='" & CName & "' AND [CustomerPartNumber]='" & CustPN & "' AND [ProductID]='" & PID & "' AND [Description]='" & Desc & "'"


    If .NoMatch = False Then
    MsgBox "Customer Part Number Exists"
    Else
    MsgBox "Customer Part Number does not Exist"
    End If
    End With
    tblCustomerPartNumbers is obviously a Table

    When I Debug/Compile it highlights "tblCustomerPartNumbers" and states "Variable not defined"

    What am iI doing wrong?

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,550
    Never, ever seen anyone use that with a table. You are the first.

    Normal use would be to open a recordset on that table and then process that With statement on the recordset variable.
    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

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Right, can't directly address a table like that.

    Use domain aggregate function DLookup() or open a Recordset object.

    Something like:
    Code:
    If Not IsNull(DLookup("CustomerPartNumber", "tblCustomerPartNumbers", "[StationID]='" & CName & "' AND [ProductID]='" & PID & "' AND [Description]='" & Desc & "'")) Then
         MsgBox "Customer Part Number Exists"
    Else
         MsgBox "Customer Part Number does not Exist"
    End If
    Where are the variables CName, CustPN, PID, Desc declared and populated?

    If you have CustPN why would you need other criteria?

    Why not use a combobox that only offers existing CustomerPartNumber values for user to choose from?

    Please use CODE tags when posting code snips. Use the # icon on post edit menu.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,927
    You could also use dcount - returns 0 if none found

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

Similar Threads

  1. Replies: 5
    Last Post: 11-01-2021, 08:09 AM
  2. Replies: 11
    Last Post: 04-29-2015, 01:38 PM
  3. if statement in sql statement, query builder
    By 54.69.6d.20 in forum Access
    Replies: 4
    Last Post: 09-11-2012, 07:38 AM
  4. Replies: 7
    Last Post: 08-17-2011, 01:49 PM
  5. how to use IF then statement
    By ronnie4 in forum Access
    Replies: 1
    Last Post: 03-17-2009, 11:32 PM

Tags for this Thread

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