Results 1 to 8 of 8
  1. #1
    jgelpi16 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544

    Question Display Query Name


    I have a button that I click to run several queries. I would like to display in some form what query is running. I tried using the echo command but it did not appear to work properly. I do not need to discover the query name programmatically. I don't want a "vbOKOnly" msgbox displaying either because I still want the program to run without me being at my computer. I thought about the possibility of writing the query name and date/time stamp to a table when completed. However, I am at a loss as to how to do that. Any suggestions will be greatly appreciated.

  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,521
    One option would be to use SysCmd to put the current query in the status bar. More info in VBA help. If you want to write the name to a table, you could either use a recordset or execute SQL.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    jgelpi16 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    What is the correct coding for executing SQL? I thought I had it, but when I run the below code it appears to just skip over it, no data written to the table.

    Code:
    Dim varQuery
    Dim varQueryTime
    varQuery = "Query1"
    varQueryTime = Time()
    DoCmd.RunSQL "INSERT INTO TestTable (QueryName, QueryTime) VALUES (" & varQuery & "), (" & varQueryTime & ")"
    I keep getting the run-time error that states "Number of query values and destination fields are not the same."

  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,521
    That simply populates a string variable with the SQL; to execute it:

    CurrentDb.Execute mySQL, dbFailOnError
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    jgelpi16 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Still getting the run-time error:

    "Number of query values and destination fields are not the same."
    Code:
    DoCmd.SetWarnings False
    Dim varQuery
    Dim varQueryTime
    varQuery = "Query1"
    varQueryTime = Time()
    mySQL = "INSERT INTO TestTable (QueryName, QueryTime) VALUES ('" & varQuery & "'), ('" & varQueryTime & "')"
    CurrentDb.Execute mySQL, dbFailOnError
    DoCmd.SetWarnings True

  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,521
    For starters, you don't need the 2 SetWarnings lines; the Execute method doesn't throw them. If QueryTime is a Date/Time field, it needs to be surrounded by # rather than '. Your error is because you close out and reopen the parentheses in the VALUES clause; you only want the ones at the beginning and end.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    jgelpi16 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Thank you for your help! Much appreciated. I have included the working code for anyone else who may have interest.

    Code:
    Dim varQuery
    Dim varQueryTime
    varQuery = "Query1"
    varQueryTime = Time()
    mySQL = "INSERT INTO TestTable (QueryName, QueryTime) VALUES ('" & varQuery & "',#" & varQueryTime & "#)"
    CurrentDb.Execute mySQL, dbFailOnError

  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,521
    Glad we got it working for you.
    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! Display a query result into form
    By leanne in forum Forms
    Replies: 15
    Last Post: 06-23-2010, 09:18 PM
  2. Display Query Results on a Form
    By P5C768 in forum Queries
    Replies: 5
    Last Post: 05-04-2010, 11:04 AM
  3. Replies: 5
    Last Post: 01-28-2010, 09:10 AM
  4. Query to display in single row
    By access in forum Queries
    Replies: 10
    Last Post: 01-14-2010, 11:40 AM
  5. display query results in a form
    By P5C768 in forum Queries
    Replies: 3
    Last Post: 08-14-2009, 03:02 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