DoCmd.OpenQuery ??? (1 Viewer)

ccflyer

Registered User.
Local time
Today, 11:34
Joined
Aug 12, 2005
Messages
90
I'm somewhat new to VB so please hang with me. I am trying to run a query using VB when I click a command button, then close the query so the user doesn't see it happening but it doesn't seem to be working. This is what I have for code so far:

(My Query is named "DateWellPrevious")
Code:
Private Sub test_Click()
DoCmd.SetWarnings False
DoCmd.OpenQuery(DateWellPrevious,acViewNormal,[acEdit])
DoCmd.Close(acQuery,[DateWellPrevious],[acSaveYes])
End Sub
It says that it expects an equals sign after the DoCmd.OpenQuery statement and the DoCmd.Close statement.

Any Suggestions?
-Chris
 

NYC

SQL Server User
Local time
Today, 13:34
Joined
Jul 19, 2005
Messages
5
ccflyer said:
I'm somewhat new to VB so please hang with me. I am trying to run a query using VB when I click a command button, then close the query so the user doesn't see it happening but it doesn't seem to be working. This is what I have for code so far:

(My Query is named "DateWellPrevious")
Code:
Private Sub test_Click()
DoCmd.SetWarnings False
DoCmd.OpenQuery(DateWellPrevious,acViewNormal,[acEdit])
DoCmd.Close(acQuery,[DateWellPrevious],[acSaveYes])
End Sub
It says that it expects an equals sign after the DoCmd.OpenQuery statement and the DoCmd.Close statement.

Any Suggestions?
-Chris
I would think it's just

DoCmd.OpenQuery "DateWellPrevious"

you don't have to add the options.
 

Bat17

Registered User.
Local time
Today, 18:34
Joined
Sep 24, 2004
Messages
1,687
more to the point, why are you trying to open an close the query anyway? what are you trying to achieve?

Peter
 

ccflyer

Registered User.
Local time
Today, 11:34
Joined
Aug 12, 2005
Messages
90
I am trying to run a query without the user seeing anything, but actually the more I think of I, you are right, I don't need a Close command - Thanks.

But I did try
DoCmd.OpenQuery "DateWellPrevious"
and it didn't work.

EDIT: I did get it, I ended up using this
DoCmd.OpenQuery "QueryNameHerre", acViewNormal, acEdit

-Chris
 
Last edited:

Pat Hartman

Super Moderator
Staff member
Local time
Today, 13:34
Joined
Feb 19, 2002
Messages
43,452
There doesn't seem to be any reason to run this query. Why do you think you need to run it? When you run queries in code they are normally action queries that are going to update something. If you need to loop through a recordset with code, you would use the .OpenRecordSet method. You wouldn't use OpenQuery.
 

timhysniu

New member
Local time
Today, 10:34
Joined
Jul 22, 2005
Messages
8
It expects an equal sign because when you use brackets you are calling a function.

x = DoCmd.OpenQuery("DateWellPrevious")

Use this (and without the optional parameters too):

DoCmd.OpenQuery "DateWellPrevious"

ccflyer said:
I'm somewhat new to VB so please hang with me. I am trying to run a query using VB when I click a command button, then close the query so the user doesn't see it happening but it doesn't seem to be working. This is what I have for code so far:

(My Query is named "DateWellPrevious")
Code:
Private Sub test_Click()
DoCmd.SetWarnings False
DoCmd.OpenQuery(DateWellPrevious,acViewNormal,[acEdit])
DoCmd.Close(acQuery,[DateWellPrevious],[acSaveYes])
End Sub
It says that it expects an equals sign after the DoCmd.OpenQuery statement and the DoCmd.Close statement.

Any Suggestions?
-Chris
 

ccflyer

Registered User.
Local time
Today, 11:34
Joined
Aug 12, 2005
Messages
90
Hey thanks, that did work without the parentheses.

-Chris
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 13:34
Joined
Feb 19, 2002
Messages
43,452
Running a select query this way doesn't DO anything for you. You are opening it and closing it in code to no end. It is simply a waste of system resources.
 

Users who are viewing this thread

Top Bottom