Results 1 to 4 of 4
  1. #1
    Carmine is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Apr 2019
    Posts
    11

    Question Evaluating a Table Value

    I’m just attempting to learn Access VBA. So here’s the problem:
    I want to set up an IF-Then statement to evaluate the contents of a field in a table.

    Table name is: MasterTable
    Field name is: Option
    The value of Option is 1,2, or 3
    What I’m trying to do is execute the following If-Then statement:

    If option=1 then open a query
    This is to be executed on a button click



    Below is what I’ve done, but it doesn’t work. I get Run Time Error: 424
    Object required.

    Private Sub Command9_Click()
    If MasterTable.Option = 1 Then DoCmd.OpenQuery "GallonUpdateQ"
    End Sub

    Thanks

  2. #2
    madpiet is offline Expert
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    566
    Quote Originally Posted by Carmine View Post
    I’m just attempting to learn Access VBA. So here’s the problem:
    I want to set up an IF-Then statement to evaluate the contents of a field in a table.

    Table name is: MasterTable
    Field name is: Option
    The value of Option is 1,2, or 3
    What I’m trying to do is execute the following If-Then statement:

    If option=1 then open a query
    This is to be executed on a button click

    Below is what I’ve done, but it doesn’t work. I get Run Time Error: 424
    Object required.

    Private Sub Command9_Click()
    If MasterTable.Option = 1 Then DoCmd.OpenQuery "GallonUpdateQ"
    End Sub

    Thanks
    That doesn't make sense. You'd have to read a specific record... then maybe that would work. If you base a form on the table, and that record is current, then you could do it. Otherwise, you'd have to filter the table. I would start with just controls and not try to deal with records yet. It's a lot easier to start there.

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Can't reference a table/query (filtered or not) directly like that in VBA. Use code to open a recordset or use DLookup() domain aggregate function or reference a control on bound form.

    Instead of opening table or query objects, should probably open forms or reports.
    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 offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,936
    Assuming your master table contains only 1 record then use the dlookup function to get it

    If dlookup(“option”,”MasterTable”)= 1

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

Similar Threads

  1. Convert Formula to String without Evaluating
    By tkilback in forum Modules
    Replies: 5
    Last Post: 05-15-2015, 03:18 PM
  2. Replies: 3
    Last Post: 06-19-2014, 12:21 PM
  3. Replies: 2
    Last Post: 01-11-2014, 03:56 PM
  4. Evaluating Null in a Case Function
    By orcinus in forum Programming
    Replies: 8
    Last Post: 05-11-2012, 10:27 AM
  5. Evaluating Math Strings
    By Rawb in forum Programming
    Replies: 18
    Last Post: 09-01-2010, 07:50 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