Link a report to a form

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

Graham R Seach

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
 
P

PAOLO

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

PAOLO

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
 
G

Graham R Seach

Paolo,

Since [FieldName] is obviously a string value, you must tell the query
engine that it's a string:
"[FieldName] = """ & Me!FieldName & """"

That should fix both issues.

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

PAOLO said:
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
---------------------------

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

Graham R Seach

Paolo,

No, we don't teach. The only training we offer is for the applications we
develop.

There aren't any Microsoft exams for Access anymore, although there is a
rumour of one. About the best you're likely to do is take a course at TAFE
or one of the local community colleges.

Or you could hang around here in these newsgroups.

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

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 is
not part of the rowlines or the value of the crosstab query.
I am not sure how to get around this any help?
 
Top