Link a report to a form

  • Thread starter Thread starter PAOLO
  • Start date Start date
P

PAOLO

Hi I am trying to link a report to a form (from a form user can click a
print button and the report would only show the information criteria
selected on the form) Normally in the criteria on the Query used for the
report I used the followiing formula [Forms]![FormName]![FieldName] (the
field name is always a primary key). However, in this particular case Access
gives me an error message. The report I am trying to link depends on a
crosstabe query. I have tried the criteria both on the normaly query and on
the crosstab and the same error message appears. The field I am linking is
not part of the rowlines or the value of the crosstab query.
I am not sure how to get around this any help?
 
Paolo,

Just create a command button on the form, and call it, say "cmdPrint". Then
in the button's Click event, add the following pseudo-code:
Private Sub cmdPrint_Click()
DoCmd.OpenReport "rptMyReport", acViewPreview, , _
"[FieldName] = " & Me!FieldName, acWindowNormal
End Sub

I usually have a checkbox on the form, just near the button, to allow users
to select whether to preview the report, or just send it to the printer. I
name it "chkPreview", and set it's DefaultValue property = False. Using this
approach, the code becomes:
Private Sub cmdPrint_Click()
DoCmd.OpenReport "rptMyReport", _
IIf(Me!chlPreview = True, 0, 2), , _
"[FieldName] = " & Me!FieldName, acWindowNormal
End Sub

When you tick the checkbox, the report will preview.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
Hey Graham,

First of all thank you for the reply I now get a different error message, it
says "Syntax Error (missing operator) in query expression
'([FieldName]=12A)'
I checked the query and the field is there and it's spelled correctly in
Visual Basic bit (I actually cut and paste it) What is the significance of
the 12A? in the error message?

The other question I wanted to ask you, you email is signed Microsoft Access
MVP in Sydney. I am actually in Melbourne and is looking to move up there. I
would like to upgrade my skills in the VBA and module side of the program
but don't seem to be able to find a course at that level in here. Do you
guys have anything available on regular basis in your company?

Thanks again for your help much apreciate it....
Graham R Seach said:
Paolo,

Just create a command button on the form, and call it, say "cmdPrint". Then
in the button's Click event, add the following pseudo-code:
Private Sub cmdPrint_Click()
DoCmd.OpenReport "rptMyReport", acViewPreview, , _
"[FieldName] = " & Me!FieldName, acWindowNormal
End Sub

I usually have a checkbox on the form, just near the button, to allow users
to select whether to preview the report, or just send it to the printer. I
name it "chkPreview", and set it's DefaultValue property = False. Using this
approach, the code becomes:
Private Sub cmdPrint_Click()
DoCmd.OpenReport "rptMyReport", _
IIf(Me!chlPreview = True, 0, 2), , _
"[FieldName] = " & Me!FieldName, acWindowNormal
End Sub

When you tick the checkbox, the report will preview.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------

PAOLO said:
Hi I am trying to link a report to a form (from a form user can click a
print button and the report would only show the information criteria
selected on the form) Normally in the criteria on the Query used for the
report I used the followiing formula [Forms]![FormName]![FieldName] (the
field name is always a primary key). However, in this particular case
Access
gives me an error message. The report I am trying to link depends on a
crosstabe query. I have tried the criteria both on the normaly query and
on
the crosstab and the same error message appears. The field I am linking is
not part of the rowlines or the value of the crosstab query.
I am not sure how to get around this any help?
 
Apparently I had an extra comma in the coding session now the report pops up
but with no information on it at all....
PAOLO said:
Hey Graham,

First of all thank you for the reply I now get a different error message, it
says "Syntax Error (missing operator) in query expression
'([FieldName]=12A)'
I checked the query and the field is there and it's spelled correctly in
Visual Basic bit (I actually cut and paste it) What is the significance of
the 12A? in the error message?

The other question I wanted to ask you, you email is signed Microsoft Access
MVP in Sydney. I am actually in Melbourne and is looking to move up there. I
would like to upgrade my skills in the VBA and module side of the program
but don't seem to be able to find a course at that level in here. Do you
guys have anything available on regular basis in your company?

Thanks again for your help much apreciate it....
Graham R Seach said:
Paolo,

Just create a command button on the form, and call it, say "cmdPrint". Then
in the button's Click event, add the following pseudo-code:
Private Sub cmdPrint_Click()
DoCmd.OpenReport "rptMyReport", acViewPreview, , _
"[FieldName] = " & Me!FieldName, acWindowNormal
End Sub

I usually have a checkbox on the form, just near the button, to allow users
to select whether to preview the report, or just send it to the printer. I
name it "chkPreview", and set it's DefaultValue property = False. Using this
approach, the code becomes:
Private Sub cmdPrint_Click()
DoCmd.OpenReport "rptMyReport", _
IIf(Me!chlPreview = True, 0, 2), , _
"[FieldName] = " & Me!FieldName, acWindowNormal
End Sub

When you tick the checkbox, the report will preview.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------

PAOLO said:
Hi I am trying to link a report to a form (from a form user can click a
print button and the report would only show the information criteria
selected on the form) Normally in the criteria on the Query used for the
report I used the followiing formula [Forms]![FormName]![FieldName] (the
field name is always a primary key). However, in this particular case
Access
gives me an error message. The report I am trying to link depends on a
crosstabe query. I have tried the criteria both on the normaly query and
on
the crosstab and the same error message appears. The field I am
linking
 

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

Back
Top