Command button that prints current record in a report

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have been working on this for a while now. It seems really simple but for some reason the simplicity is eluding me. I keep getting a syntax error in the strFilter line. Here is the code, can anybody see anything wrong with it

Private Sub Command55_Click(
On Error GoTo Err_Command55_Clic

Dim strDocName As Strin
Dim strFilter As Strin

strDocName = "NonConformity Tag
strFilter = "Inspection_Records = Forms!Inspection Data Entry Form!Inspection_Records
DoCmd.OpenReport strDocName, acViewNormal, , strFilte

Exit_Command55_Click
Exit Su

Err_Command55_Click
MsgBox Err.Descriptio
Resume Exit_Command55_Clic

End Su

I have checked and double checked the spelling for the form and table names
These are the names
Table = Inspection_Record
Form = Inspection Data Entry For
Report = NonConformity Ta

HELP!!
Thank
Chaz
 
Your StrFilter is all in quotes. It is placing that strin as the filter.
You need something more like:
strFilter = "Inspection_Records =" & " '" &Forms!Inspection Data Entry
Form!Inspection_Records & "'"




this will get you:

Inspection_Records = 'SomeValue'




Chaz said:
I have been working on this for a while now. It seems really simple but
for some reason the simplicity is eluding me. I keep getting a syntax error
in the strFilter line. Here is the code, can anybody see anything wrong with
it?
 
Hello Char,

Your filter string gives error because it is trying to select a records
containing
Forms!Inspection Data Entry Form!Inspection_Records

The filter string needs to be:
strFilter = "Inspection_Records = " & Forms!Inspection Data Entry
Form!Inspection_Records
Which will mean the string will evealuate to:
Inspection_Records = 234
wher 234 was the number contained in the Forms!Inspection Data Entry
Form!Inspection_Records control.
I am assuming that the contents of Forms!Inspection Data Entry
Form!Inspection_Records is a number. If it is a character string you need to
enclose the criteria string in single quotes, so the string will be:
strFilter = "Inspection_Records = '" & Forms!Inspection Data Entry
Form!Inspection_Records & "'"

Ragnar
 
Sorry about that, I didn't notice the space in the name of the form. When
form or field names contain spaces you need to ether enclose the name in []
or replace the space with an underscore character, like this

strFilter = "Inspection_Records = Forms![Inspection Data Entry
Form]!Inspection_Records"

or this

strFilter = "Inspection_Records = Forms!Inspection_Data_Entry
Form!Inspection_Records"

Ragnar
..
 
Thank you, Thank you, Thank you. It now works. One of the other things I had wrong was that Inspection_records is a table. I had to add a autonumber field and make it the primary key and put that field in the place of inspection_records. That was the field that it was searching on for the record to print. But it all works now and even a week ahead of schedule. Again Thank you.
 
Back
Top