Command Button to Open Report Error

G

Guest

Hello all,
I have the following code on the On Click event of a command button:
Dim stDocName As String

If Not IsNull(Me.ID) Then
stDocName = "rptTopTen"
DoCmd.OpenReport stDocName, acViewPreview, ,
"[tbl_PlayLists].[RecordID] = " & Me.ID
Else
MsgBox "Select a collection.", vbOKOnly
Me.ID.SetFocus
End If

The error I recieve is:
Syntax error (missing operator) in query expression
'([tbl_PlayLists].[RecordID] = ID: 3)'

I appreciate any insight!
Renee
 
D

Dirk Goldgar

Renee said:
Hello all,
I have the following code on the On Click event of a command
button: Dim stDocName As String

If Not IsNull(Me.ID) Then
stDocName = "rptTopTen"
DoCmd.OpenReport stDocName, acViewPreview, ,
"[tbl_PlayLists].[RecordID] = " & Me.ID
Else
MsgBox "Select a collection.", vbOKOnly
Me.ID.SetFocus
End If

The error I recieve is:
Syntax error (missing operator) in query expression
'([tbl_PlayLists].[RecordID] = ID: 3)'

I appreciate any insight!
Renee

It looks like the ID control on the form has a value of "ID: 3". Is
that a calculated control? Normally I'd expect the value of the
RecordID *field* to be a simple number, probably 3 in this case. Does
the ID text box on the form have a controlsource like

="ID: " & [RecordID]

?

If the form's recordsource actually includes the RecordID field, then
you can probably rewrite your OpenReport statement as:

DoCmd.OpenReport stDocName, acViewPreview, , _
"[tbl_PlayLists].[RecordID] = " & Me!RecordID

But that's just a guess.
 
G

Guest

The control is based on a query, which is set to requery when the control
gets focus. Before the control requeries, it is set to verify the criteria
fields are not null. The query is based on the other controls of the form.
The ID box is a combo box, limited to its list.

Hope this helps you, help me <smile>
Thank you for your time
Renee


Dirk Goldgar said:
Renee said:
Hello all,
I have the following code on the On Click event of a command
button: Dim stDocName As String

If Not IsNull(Me.ID) Then
stDocName = "rptTopTen"
DoCmd.OpenReport stDocName, acViewPreview, ,
"[tbl_PlayLists].[RecordID] = " & Me.ID
Else
MsgBox "Select a collection.", vbOKOnly
Me.ID.SetFocus
End If

The error I recieve is:
Syntax error (missing operator) in query expression
'([tbl_PlayLists].[RecordID] = ID: 3)'

I appreciate any insight!
Renee

It looks like the ID control on the form has a value of "ID: 3". Is
that a calculated control? Normally I'd expect the value of the
RecordID *field* to be a simple number, probably 3 in this case. Does
the ID text box on the form have a controlsource like

="ID: " & [RecordID]

?

If the form's recordsource actually includes the RecordID field, then
you can probably rewrite your OpenReport statement as:

DoCmd.OpenReport stDocName, acViewPreview, , _
"[tbl_PlayLists].[RecordID] = " & Me!RecordID

But that's just a guess.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
G

Guest

Here is a good laugh for you, I concatenated "ID: " with the query result (3
in this example). So it was literally looking for a collection with the ID of
"ID:3", which would never happen. I removed the concatenation and every thing
works as intended again!

Thanks again for your time,
Renee

Renee said:
The control is based on a query, which is set to requery when the control
gets focus. Before the control requeries, it is set to verify the criteria
fields are not null. The query is based on the other controls of the form.
The ID box is a combo box, limited to its list.

Hope this helps you, help me <smile>
Thank you for your time
Renee


Dirk Goldgar said:
Renee said:
Hello all,
I have the following code on the On Click event of a command
button: Dim stDocName As String

If Not IsNull(Me.ID) Then
stDocName = "rptTopTen"
DoCmd.OpenReport stDocName, acViewPreview, ,
"[tbl_PlayLists].[RecordID] = " & Me.ID
Else
MsgBox "Select a collection.", vbOKOnly
Me.ID.SetFocus
End If

The error I recieve is:
Syntax error (missing operator) in query expression
'([tbl_PlayLists].[RecordID] = ID: 3)'

I appreciate any insight!
Renee

It looks like the ID control on the form has a value of "ID: 3". Is
that a calculated control? Normally I'd expect the value of the
RecordID *field* to be a simple number, probably 3 in this case. Does
the ID text box on the form have a controlsource like

="ID: " & [RecordID]

?

If the form's recordsource actually includes the RecordID field, then
you can probably rewrite your OpenReport statement as:

DoCmd.OpenReport stDocName, acViewPreview, , _
"[tbl_PlayLists].[RecordID] = " & Me!RecordID

But that's just a guess.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top