syntax

pungentSapling

NeedHotSauce?
Local time
Today, 04:53
Joined
Apr 4, 2002
Messages
116
I am having a hard time figuring out when to use [] and whent to use () and when you don't need any brackets.
I am trying to open the following queries when a cmd button is clicked. Do I have to Dim the queries as strings and call them from their variable name?

DoCmd.OpenQuery qryMissedEntries1, [acViewNormal]
gets me undefined variable error



DoCmd.OpenQuery ([qryMissedEntries2])
these seem to pass compilation but does not opena query

DoCmd.OpenQuery (qryMissedEntriesC)

none of the above formats seem to work.
thanks p
 
DoCmd.OpenQuery "qryMissedEntriesC"
 
Square brackets go round FIELD NAMES that contain non-alphanumeric characters. (eg. those with spaces) Field Names without spaces can be optionally square-bracketed.

The specific syntax for a command can be found in HELP. So for example, for your DOCmd.Open query Help gives:

DoCmd.OpenQuery queryname[, view][, datamode].

So you just have to put the query name as a STRING(in quotes)- NO BRACKETS. As help explains:

queryname A string expression that's the valid name of a query in the current database.

'But, what is this!' I hear you cry 'why are view and datamode in square brackets?' That's because they are OPTIONAL ARGUMENTS- you don't have to put them in, because there are standard defaults if you don't.

That's just how Help is formatted. Don't put those brackets in!

Confused? We haven't even got to curly brackets yet! There are so many different ways to form expressions and commands, it takes time to master them. HELP is an ever-present friend in need.
 
thanks for the help, I have the queries opening the way they should...great.

I have been turning to the help files. But I have been finding that the syntax examples are hard to follow. They get me close but then I have to trial and error for awhile until it works!
Your explanation will certainly help Thanks.
 

Users who are viewing this thread

Back
Top Bottom