Error in My Code?

J

Jill

Hi,

Please see if there is anything wrong in the following code.

'Loop through all report names.
For Each AccessObject In CurrentProject.AllReports
'Don't add LabelsTempReport to drop-down menu.
If Not AccessObject.Name = "LabelsTempReport" Then
'Only add report names that contain the word "labels".
If InStr(AccessObject.Name, "Labels") > 1 Then
'Add currect report name and semicolon to ValueList variable.
ValueList = ValueList & Chr(34) & AccessObject.Name &
Chr(34) & ";"
End If
End If
Next
 
D

Dirk Goldgar

Jill said:
Hi,

Please see if there is anything wrong in the following code.

'Loop through all report names.
For Each AccessObject In CurrentProject.AllReports
'Don't add LabelsTempReport to drop-down menu.
If Not AccessObject.Name = "LabelsTempReport" Then
'Only add report names that contain the word "labels".
If InStr(AccessObject.Name, "Labels") > 1 Then
'Add currect report name and semicolon to ValueList
variable.
ValueList = ValueList & Chr(34) & AccessObject.Name &
Chr(34) & ";"
End If
End If
Next


Yes, there is. "AccessObject" is the class name; you have to declare an
object variable of that type, and use it in your loop. Try this revision:

'----- start of revised code -----
Dim ao As AccessObject

'Loop through all report names.
For Each ao In CurrentProject.AllReports
'Don't add LabelsTempReport to drop-down menu.
If ao.Name <> "LabelsTempReport" Then
'Only add report names that contain the word "labels".
If InStr(ao.Name, "Labels") > 1 Then
'Add current report name and semicolon to ValueList
variable.
ValueList = ValueList & _
Chr(34) & ao.Name & Chr(34) & ";"
End If
End If
Next
'----- end of revised code -----

I'm assuming you have previously declared a string variable named
"ValueList". If not, you should declare that also.
 
J

Jill

I changed that as you suggested. There is still error. It seems to think
there is an error in my second If (If Instr...). (Yes, I declared VauleList
as string.)

Thank you.
 
D

Dirk Goldgar

Jill said:
I changed that as you suggested. There is still error. It seems to think
there is an error in my second If (If Instr...). (Yes, I declared
VauleList
as string.)


Please post the code you're using now, and tell me what error message and/or
number you get, and what line and text are highlighted? I don't see
anything wrong with the code snippet I posted (except the line wrapping
caused by the newsreader, which I hope you corrected), and it compiles and
works fine for me.
 
J

Jill

Dirk,
It works now. Thank you for your help.

Dirk Goldgar said:
Please post the code you're using now, and tell me what error message and/or
number you get, and what line and text are highlighted? I don't see
anything wrong with the code snippet I posted (except the line wrapping
caused by the newsreader, which I hope you corrected), and it compiles and
works fine for me.

--
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