+ Reply to Thread
Results 1 to 3 of 3

REAL BASIC VBA syntax for retrieving results from query

Hybrid View

  1. #1
    Registered User
    Join Date
    01-28-2015
    Location
    Virginia
    MS-Off Ver
    2013
    Posts
    28

    REAL BASIC VBA syntax for retrieving results from query

    I need to pull a result from a query and store it as a variable to be compared to criteria for an IF / THEN statement. What is the correct syntax for pulling a result, from say column 4 in a query, and saying if the record exists, do this. If it doesn't exist, do this -- in VBA? My query will only ever return 1 result or it will return 0 results.

    If 1 result is returned, it needs to go to Time_OUT form. If 0 results are returned, it goes to Time_IN form. Thanks a ton in advance!

    As a start, this is the code I have (The part where it says "If Me.MO_ID=Null" Then is where I don't know the correct syntax to use):

    Option Compare Database
    
    Private Sub Command3_Click()
    On Error GoTo Err_Command3_Click
    
    
        
        DoCmd.OpenQuery "Open MO Evaluation Query", acViewNormal, acEdit
          
        If Me.MO_ID = Null Then
        DoCmd.OpenForm "Time_IN_Form", acNormal, "", "", , acNormal
        
        Else
        
        MsgBox "You must log out out of your current MO first."
        DoCmd.OpenForm "Time_OUT_Form", acNormal, "", "", , acNormal
        DoCmd.GoToControl "Time_OUT"
        
        End If
       
    Exit_Command3_Click:
        Exit Sub
    
    
    Err_Command3_Click:
        MsgBox Err.Description
        Resume Exit_Command3_Click
        
    End Sub

  2. #2
    Valued Forum Contributor ranman256's Avatar
    Join Date
    07-29-2012
    Location
    Kentucky
    MS-Off Ver
    Excel 2003
    Posts
    1,190

    Re: REAL BASIC VBA syntax for retrieving results from query

    you cant store a query recordset in a variable to compare. Do you mean pull a value from a field from a query?
    if so,
    vID = Dlookup("[field]","query","[id]=" & txtbox )
    if vID = 76 then...

  3. #3
    Registered User
    Join Date
    01-28-2015
    Location
    Virginia
    MS-Off Ver
    2013
    Posts
    28

    Re: REAL BASIC VBA syntax for retrieving results from query

    Thanks for the reply ranman. What would I replace in the area that says "[ID]=" * textbox in the example? I can't get this to work yet

    Update: I know what to put here now
    Last edited by drowe005; 07-16-2015 at 04:46 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Need help with a real basic VBA question
    By drowe005 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-07-2015, 01:38 AM
  2. Retrieving results and FORECAST function - the results are wrong!
    By Lucky_G in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 10-03-2014, 10:57 AM
  3. [SOLVED] URL - Syntax Error (Basic)
    By keen2xl in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-10-2013, 03:55 AM
  4. Retrieving Top 3 Results
    By k992010 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-21-2013, 06:46 PM
  5. basic macro syntax error..
    By ashish1044 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-08-2013, 05:11 AM
  6. [SOLVED] REALLY Basic question on variable syntax...
    By Accountant II in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-27-2012, 04:31 PM
  7. [SOLVED] Basic VBA syntax
    By marcmc in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-02-2005, 06:17 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1