Help With Multiple DoCmd.Open Report Commands

G

Guest

I am to get multiple reports to run off of a single onClick event.

I have letters that are made into reports and i also have another report
that would print out the envelopes for those records.

I need to code something that would launch the first report (for printing)
and then lauch a message box to confirm the launching of the second report.

I have the following questions -

1 How do I pass the recordset produced by the first reports query to the
second report without making the user re-enter all the parameters. I need
the letters to match the envelopes of course.

2. How Do I make the MsgBox that is used to confirm / deny the opening of
the second report.


please advise and if it is too vauge what I have typed - please let me know
and I will try to explain myself better.

-oh and why not do this with a Word mail merge? - the company dosent have
liscence for word - they use some proprietary word processing software - but
they have access for Databases - go figure.


thanx
 
A

Allen Browne

Use a form where the user can enter the parameters for the report. Then when
they click the button, both reports can read the text boxes on the report
for their parameters.

The Click event procedure for your command button will end up like this:

Private Sub cmdPrint_Click()
Dim strWhere As String
strWhere = "City = """ & Me.[City] & """"
DoCmd.OpenReport "Report1", acViewPreview, , strWhere
DoCmd.OpenReport "Report2", acViewPreview, , strWhere
End Sub

Some examples of how to build the WhereCondition:

a) Just based on the primary key value:
http://allenbrowne.com/casu-15.html

b) Based on a date range:
http://allenbrowne.com/casu-07.html

c) Based on a whole bunch of different controls that might or might not have
any value entered:
http://allenbrowne.com/unlinked/Search2000.zip

The last one is a downloadable database (Access 2000 or later) without an
explanatory article.
 
G

Guest

oh and how / where do I make the msgbox for use ?

Allen Browne said:
Use a form where the user can enter the parameters for the report. Then when
they click the button, both reports can read the text boxes on the report
for their parameters.

The Click event procedure for your command button will end up like this:

Private Sub cmdPrint_Click()
Dim strWhere As String
strWhere = "City = """ & Me.[City] & """"
DoCmd.OpenReport "Report1", acViewPreview, , strWhere
DoCmd.OpenReport "Report2", acViewPreview, , strWhere
End Sub

Some examples of how to build the WhereCondition:

a) Just based on the primary key value:
http://allenbrowne.com/casu-15.html

b) Based on a date range:
http://allenbrowne.com/casu-07.html

c) Based on a whole bunch of different controls that might or might not have
any value entered:
http://allenbrowne.com/unlinked/Search2000.zip

The last one is a downloadable database (Access 2000 or later) without an
explanatory article.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

HelloWorld said:
I am to get multiple reports to run off of a single onClick event.

I have letters that are made into reports and i also have another report
that would print out the envelopes for those records.

I need to code something that would launch the first report (for printing)
and then lauch a message box to confirm the launching of the second
report.

I have the following questions -

1 How do I pass the recordset produced by the first reports query to the
second report without making the user re-enter all the parameters. I need
the letters to match the envelopes of course.

2. How Do I make the MsgBox that is used to confirm / deny the opening of
the second report.


please advise and if it is too vauge what I have typed - please let me
know
and I will try to explain myself better.

-oh and why not do this with a Word mail merge? - the company dosent have
liscence for word - they use some proprietary word processing software -
but
they have access for Databases - go figure.


thanx
 
G

Guest

So Do I not need any parameters for the queries the reports are based on ?

Also - is there any way to make the form to open off of the same buttons
cick event ?


Allen Browne said:
Use a form where the user can enter the parameters for the report. Then when
they click the button, both reports can read the text boxes on the report
for their parameters.

The Click event procedure for your command button will end up like this:

Private Sub cmdPrint_Click()
Dim strWhere As String
strWhere = "City = """ & Me.[City] & """"
DoCmd.OpenReport "Report1", acViewPreview, , strWhere
DoCmd.OpenReport "Report2", acViewPreview, , strWhere
End Sub

Some examples of how to build the WhereCondition:

a) Just based on the primary key value:
http://allenbrowne.com/casu-15.html

b) Based on a date range:
http://allenbrowne.com/casu-07.html

c) Based on a whole bunch of different controls that might or might not have
any value entered:
http://allenbrowne.com/unlinked/Search2000.zip

The last one is a downloadable database (Access 2000 or later) without an
explanatory article.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

HelloWorld said:
I am to get multiple reports to run off of a single onClick event.

I have letters that are made into reports and i also have another report
that would print out the envelopes for those records.

I need to code something that would launch the first report (for printing)
and then lauch a message box to confirm the launching of the second
report.

I have the following questions -

1 How do I pass the recordset produced by the first reports query to the
second report without making the user re-enter all the parameters. I need
the letters to match the envelopes of course.

2. How Do I make the MsgBox that is used to confirm / deny the opening of
the second report.


please advise and if it is too vauge what I have typed - please let me
know
and I will try to explain myself better.

-oh and why not do this with a Word mail merge? - the company dosent have
liscence for word - they use some proprietary word processing software -
but
they have access for Databases - go figure.


thanx
 
A

Allen Browne

Corrrect. When you use the WhereCondition of OpenReport, you no longer need
the parameters in the query.

If you want your original form to open the form for entering the parameters,
just use:
Docmd.OpenForm "MyParameterForm"
Then on MyParameterForm, put Ok and Cancel buttons. The Cancel just closes
it. The Click event of the Ok button is the code suggested in the previous
reply.

To ask the user about opening Report2 as well:
If MsgBox("Report2 also?", vbYesNo) = vbyes Then
DoCmd.OpenReport "Report2", acViewPreview, , strWhere
End If

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

HelloWorld said:
So Do I not need any parameters for the queries the reports are based on ?

Also - is there any way to make the form to open off of the same buttons
cick event ?


Allen Browne said:
Use a form where the user can enter the parameters for the report. Then
when
they click the button, both reports can read the text boxes on the report
for their parameters.

The Click event procedure for your command button will end up like this:

Private Sub cmdPrint_Click()
Dim strWhere As String
strWhere = "City = """ & Me.[City] & """"
DoCmd.OpenReport "Report1", acViewPreview, , strWhere
DoCmd.OpenReport "Report2", acViewPreview, , strWhere
End Sub

Some examples of how to build the WhereCondition:

a) Just based on the primary key value:
http://allenbrowne.com/casu-15.html

b) Based on a date range:
http://allenbrowne.com/casu-07.html

c) Based on a whole bunch of different controls that might or might not
have
any value entered:
http://allenbrowne.com/unlinked/Search2000.zip

The last one is a downloadable database (Access 2000 or later) without an
explanatory article.

HelloWorld said:
I am to get multiple reports to run off of a single onClick event.

I have letters that are made into reports and i also have another
report
that would print out the envelopes for those records.

I need to code something that would launch the first report (for
printing)
and then lauch a message box to confirm the launching of the second
report.

I have the following questions -

1 How do I pass the recordset produced by the first reports query to
the
second report without making the user re-enter all the parameters. I
need
the letters to match the envelopes of course.

2. How Do I make the MsgBox that is used to confirm / deny the opening
of
the second report.


please advise and if it is too vauge what I have typed - please let me
know
and I will try to explain myself better.

-oh and why not do this with a Word mail merge? - the company dosent
have
liscence for word - they use some proprietary word processing
software -
but
they have access for Databases - go figure.
 
G

Guest

Ok I am trying to implement the strwhere in my report but seem to be having a
problem.

Here is my code
#####################################################
Private Sub OK_Click()
Dim strWhere As String
strWhere = "Recruitment ID = """ & Me.[ID_Combo] & """" And
"Recruitment_Counter = & Me.[Counter_Combo]"
And "Position Title = """ & Me.[Position_Combo] & """"
DoCmd.OpenReport "[Report_List]", acViewPreview, , strWhere

DoCmd.OpenReport "Report2", acViewPreview, , strWhere

End Sub

#####################################################

I am getting a type mismatch error # 13 when i try to run the report.

the datatypes of the fields are

Recruitment ID - Text
Recruitment_Counter - Number
Position Title - Text

Can you tell me what I am doing wrong ?



Allen Browne said:
Corrrect. When you use the WhereCondition of OpenReport, you no longer need
the parameters in the query.

If you want your original form to open the form for entering the parameters,
just use:
Docmd.OpenForm "MyParameterForm"
Then on MyParameterForm, put Ok and Cancel buttons. The Cancel just closes
it. The Click event of the Ok button is the code suggested in the previous
reply.

To ask the user about opening Report2 as well:
If MsgBox("Report2 also?", vbYesNo) = vbyes Then
DoCmd.OpenReport "Report2", acViewPreview, , strWhere
End If

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

HelloWorld said:
So Do I not need any parameters for the queries the reports are based on ?

Also - is there any way to make the form to open off of the same buttons
cick event ?


Allen Browne said:
Use a form where the user can enter the parameters for the report. Then
when
they click the button, both reports can read the text boxes on the report
for their parameters.

The Click event procedure for your command button will end up like this:

Private Sub cmdPrint_Click()
Dim strWhere As String
strWhere = "City = """ & Me.[City] & """"
DoCmd.OpenReport "Report1", acViewPreview, , strWhere
DoCmd.OpenReport "Report2", acViewPreview, , strWhere
End Sub

Some examples of how to build the WhereCondition:

a) Just based on the primary key value:
http://allenbrowne.com/casu-15.html

b) Based on a date range:
http://allenbrowne.com/casu-07.html

c) Based on a whole bunch of different controls that might or might not
have
any value entered:
http://allenbrowne.com/unlinked/Search2000.zip

The last one is a downloadable database (Access 2000 or later) without an
explanatory article.

I am to get multiple reports to run off of a single onClick event.

I have letters that are made into reports and i also have another
report
that would print out the envelopes for those records.

I need to code something that would launch the first report (for
printing)
and then lauch a message box to confirm the launching of the second
report.

I have the following questions -

1 How do I pass the recordset produced by the first reports query to
the
second report without making the user re-enter all the parameters. I
need
the letters to match the envelopes of course.

2. How Do I make the MsgBox that is used to confirm / deny the opening
of
the second report.


please advise and if it is too vauge what I have typed - please let me
know
and I will try to explain myself better.

-oh and why not do this with a Word mail merge? - the company dosent
have
liscence for word - they use some proprietary word processing
software -
but
they have access for Databases - go figure.
 
A

Allen Browne

The quotes are not in the right place.
You must use square brackets around the field name that contains a space.
If the number field is Null, the string will be malformed, so use Nz().
Bracketing can also help.

Try:

strWhere = "(Recruitment ID = """ & Me.[ID_Combo] & _
""") And (Recruitment_Counter = " & Nz(Me.[Counter_Combo],0) & _
") And ([Position Title] = """ & Me.[Position_Combo] & """)"

Immediately after that line, add:
Debug.Print strWhere

If it fails, open the Immediate Window (Ctrl+G) and look at what was printed
there. See if the quotes and brackets match, the ANDs turn up in the right
places, etc. It must look like the WHERE clause of a query. This is
invaluable for seeing what's wrong, so you can figure out how to fix it.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

HelloWorld said:
Ok I am trying to implement the strwhere in my report but seem to be
having a
problem.

Here is my code
#####################################################
Private Sub OK_Click()
Dim strWhere As String
strWhere = "Recruitment ID = """ & Me.[ID_Combo] & """" And
"Recruitment_Counter = & Me.[Counter_Combo]"
And "Position Title = """ & Me.[Position_Combo] & """"
DoCmd.OpenReport "[Report_List]", acViewPreview, , strWhere

DoCmd.OpenReport "Report2", acViewPreview, , strWhere

End Sub

#####################################################

I am getting a type mismatch error # 13 when i try to run the report.

the datatypes of the fields are

Recruitment ID - Text
Recruitment_Counter - Number
Position Title - Text

Can you tell me what I am doing wrong ?



Allen Browne said:
Corrrect. When you use the WhereCondition of OpenReport, you no longer
need
the parameters in the query.

If you want your original form to open the form for entering the
parameters,
just use:
Docmd.OpenForm "MyParameterForm"
Then on MyParameterForm, put Ok and Cancel buttons. The Cancel just
closes
it. The Click event of the Ok button is the code suggested in the
previous
reply.

To ask the user about opening Report2 as well:
If MsgBox("Report2 also?", vbYesNo) = vbyes Then
DoCmd.OpenReport "Report2", acViewPreview, , strWhere
End If

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

HelloWorld said:
So Do I not need any parameters for the queries the reports are based
on ?

Also - is there any way to make the form to open off of the same
buttons
cick event ?


:

Use a form where the user can enter the parameters for the report.
Then
when
they click the button, both reports can read the text boxes on the
report
for their parameters.

The Click event procedure for your command button will end up like
this:

Private Sub cmdPrint_Click()
Dim strWhere As String
strWhere = "City = """ & Me.[City] & """"
DoCmd.OpenReport "Report1", acViewPreview, , strWhere
DoCmd.OpenReport "Report2", acViewPreview, , strWhere
End Sub

Some examples of how to build the WhereCondition:

a) Just based on the primary key value:
http://allenbrowne.com/casu-15.html

b) Based on a date range:
http://allenbrowne.com/casu-07.html

c) Based on a whole bunch of different controls that might or might
not
have
any value entered:
http://allenbrowne.com/unlinked/Search2000.zip

The last one is a downloadable database (Access 2000 or later) without
an
explanatory article.

I am to get multiple reports to run off of a single onClick event.

I have letters that are made into reports and i also have another
report
that would print out the envelopes for those records.

I need to code something that would launch the first report (for
printing)
and then lauch a message box to confirm the launching of the second
report.

I have the following questions -

1 How do I pass the recordset produced by the first reports query to
the
second report without making the user re-enter all the parameters.
I
need
the letters to match the envelopes of course.

2. How Do I make the MsgBox that is used to confirm / deny the
opening
of
the second report.


please advise and if it is too vauge what I have typed - please let
me
know
and I will try to explain myself better.

-oh and why not do this with a Word mail merge? - the company dosent
have
liscence for word - they use some proprietary word processing
software -
but
they have access for Databases - go figure.
 
G

Guest

This may sound like a stupid question but what should be the recordsource of
the form ?

I have it set as the table that all of the queries ect are based off of
[Applicant Data] - dont seem to be getting what I want with this table though
- a text field I have Called [Position Title] returned a 2 when typed in the
whereclause and then it overwrote the data a record in the [Position Title]
field from "Dispatch" to the number 2.

If it is a query then how Do I accomplish this if I have mutlipe queries
that I use for the various letters

Invite To Interview Data By Recruitment ID & Position
Invite To Test Data By Recruitment ID & Position
NQ1 Letter - Insufficent Data or Quals
NQ2 Letter - Test Failure
NQ3 - Post Interview No Hire Query



Allen Browne said:
The quotes are not in the right place.
You must use square brackets around the field name that contains a space.
If the number field is Null, the string will be malformed, so use Nz().
Bracketing can also help.

Try:

strWhere = "(Recruitment ID = """ & Me.[ID_Combo] & _
""") And (Recruitment_Counter = " & Nz(Me.[Counter_Combo],0) & _
") And ([Position Title] = """ & Me.[Position_Combo] & """)"

Immediately after that line, add:
Debug.Print strWhere

If it fails, open the Immediate Window (Ctrl+G) and look at what was printed
there. See if the quotes and brackets match, the ANDs turn up in the right
places, etc. It must look like the WHERE clause of a query. This is
invaluable for seeing what's wrong, so you can figure out how to fix it.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

HelloWorld said:
Ok I am trying to implement the strwhere in my report but seem to be
having a
problem.

Here is my code
#####################################################
Private Sub OK_Click()
Dim strWhere As String
strWhere = "Recruitment ID = """ & Me.[ID_Combo] & """" And
"Recruitment_Counter = & Me.[Counter_Combo]"
And "Position Title = """ & Me.[Position_Combo] & """"
DoCmd.OpenReport "[Report_List]", acViewPreview, , strWhere

DoCmd.OpenReport "Report2", acViewPreview, , strWhere

End Sub

#####################################################

I am getting a type mismatch error # 13 when i try to run the report.

the datatypes of the fields are

Recruitment ID - Text
Recruitment_Counter - Number
Position Title - Text

Can you tell me what I am doing wrong ?



Allen Browne said:
Corrrect. When you use the WhereCondition of OpenReport, you no longer
need
the parameters in the query.

If you want your original form to open the form for entering the
parameters,
just use:
Docmd.OpenForm "MyParameterForm"
Then on MyParameterForm, put Ok and Cancel buttons. The Cancel just
closes
it. The Click event of the Ok button is the code suggested in the
previous
reply.

To ask the user about opening Report2 as well:
If MsgBox("Report2 also?", vbYesNo) = vbyes Then
DoCmd.OpenReport "Report2", acViewPreview, , strWhere
End If

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

So Do I not need any parameters for the queries the reports are based
on ?

Also - is there any way to make the form to open off of the same
buttons
cick event ?


:

Use a form where the user can enter the parameters for the report.
Then
when
they click the button, both reports can read the text boxes on the
report
for their parameters.

The Click event procedure for your command button will end up like
this:

Private Sub cmdPrint_Click()
Dim strWhere As String
strWhere = "City = """ & Me.[City] & """"
DoCmd.OpenReport "Report1", acViewPreview, , strWhere
DoCmd.OpenReport "Report2", acViewPreview, , strWhere
End Sub

Some examples of how to build the WhereCondition:

a) Just based on the primary key value:
http://allenbrowne.com/casu-15.html

b) Based on a date range:
http://allenbrowne.com/casu-07.html

c) Based on a whole bunch of different controls that might or might
not
have
any value entered:
http://allenbrowne.com/unlinked/Search2000.zip

The last one is a downloadable database (Access 2000 or later) without
an
explanatory article.

I am to get multiple reports to run off of a single onClick event.

I have letters that are made into reports and i also have another
report
that would print out the envelopes for those records.

I need to code something that would launch the first report (for
printing)
and then lauch a message box to confirm the launching of the second
report.

I have the following questions -

1 How do I pass the recordset produced by the first reports query to
the
second report without making the user re-enter all the parameters.
I
need
the letters to match the envelopes of course.

2. How Do I make the MsgBox that is used to confirm / deny the
opening
of
the second report.


please advise and if it is too vauge what I have typed - please let
me
know
and I will try to explain myself better.

-oh and why not do this with a Word mail merge? - the company dosent
have
liscence for word - they use some proprietary word processing
software -
but
they have access for Databases - go figure.
 
G

Guest

allan-

I still seem to be getting those type mismatch errors.

I copied your code verbatim and it dosent seem to be going through.
Where am I supposed to be looking for the Datatypes - in the original tables
' in the queries , or in the report itself - if you could answer that I would
be much obliged - as well as any other suggesttions that you may have.

thank you


Allen Browne said:
The quotes are not in the right place.
You must use square brackets around the field name that contains a space.
If the number field is Null, the string will be malformed, so use Nz().
Bracketing can also help.

Try:

strWhere = "(Recruitment ID = """ & Me.[ID_Combo] & _
""") And (Recruitment_Counter = " & Nz(Me.[Counter_Combo],0) & _
") And ([Position Title] = """ & Me.[Position_Combo] & """)"

Immediately after that line, add:
Debug.Print strWhere

If it fails, open the Immediate Window (Ctrl+G) and look at what was printed
there. See if the quotes and brackets match, the ANDs turn up in the right
places, etc. It must look like the WHERE clause of a query. This is
invaluable for seeing what's wrong, so you can figure out how to fix it.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

HelloWorld said:
Ok I am trying to implement the strwhere in my report but seem to be
having a
problem.

Here is my code
#####################################################
Private Sub OK_Click()
Dim strWhere As String
strWhere = "Recruitment ID = """ & Me.[ID_Combo] & """" And
"Recruitment_Counter = & Me.[Counter_Combo]"
And "Position Title = """ & Me.[Position_Combo] & """"
DoCmd.OpenReport "[Report_List]", acViewPreview, , strWhere

DoCmd.OpenReport "Report2", acViewPreview, , strWhere

End Sub

#####################################################

I am getting a type mismatch error # 13 when i try to run the report.

the datatypes of the fields are

Recruitment ID - Text
Recruitment_Counter - Number
Position Title - Text

Can you tell me what I am doing wrong ?



Allen Browne said:
Corrrect. When you use the WhereCondition of OpenReport, you no longer
need
the parameters in the query.

If you want your original form to open the form for entering the
parameters,
just use:
Docmd.OpenForm "MyParameterForm"
Then on MyParameterForm, put Ok and Cancel buttons. The Cancel just
closes
it. The Click event of the Ok button is the code suggested in the
previous
reply.

To ask the user about opening Report2 as well:
If MsgBox("Report2 also?", vbYesNo) = vbyes Then
DoCmd.OpenReport "Report2", acViewPreview, , strWhere
End If

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

So Do I not need any parameters for the queries the reports are based
on ?

Also - is there any way to make the form to open off of the same
buttons
cick event ?


:

Use a form where the user can enter the parameters for the report.
Then
when
they click the button, both reports can read the text boxes on the
report
for their parameters.

The Click event procedure for your command button will end up like
this:

Private Sub cmdPrint_Click()
Dim strWhere As String
strWhere = "City = """ & Me.[City] & """"
DoCmd.OpenReport "Report1", acViewPreview, , strWhere
DoCmd.OpenReport "Report2", acViewPreview, , strWhere
End Sub

Some examples of how to build the WhereCondition:

a) Just based on the primary key value:
http://allenbrowne.com/casu-15.html

b) Based on a date range:
http://allenbrowne.com/casu-07.html

c) Based on a whole bunch of different controls that might or might
not
have
any value entered:
http://allenbrowne.com/unlinked/Search2000.zip

The last one is a downloadable database (Access 2000 or later) without
an
explanatory article.

I am to get multiple reports to run off of a single onClick event.

I have letters that are made into reports and i also have another
report
that would print out the envelopes for those records.

I need to code something that would launch the first report (for
printing)
and then lauch a message box to confirm the launching of the second
report.

I have the following questions -

1 How do I pass the recordset produced by the first reports query to
the
second report without making the user re-enter all the parameters.
I
need
the letters to match the envelopes of course.

2. How Do I make the MsgBox that is used to confirm / deny the
opening
of
the second report.


please advise and if it is too vauge what I have typed - please let
me
know
and I will try to explain myself better.

-oh and why not do this with a Word mail merge? - the company dosent
have
liscence for word - they use some proprietary word processing
software -
but
they have access for Databases - go figure.
 
G

Guest

Allen - please ignore all of my other posts - I got it to work - thank you so
much for your help - you are truly awesome.

If I may trouble you for one more thing - Every time someone
enters criteria
into the text boxes that would return a blank recordset, Access
pops up a
report that has #error#'s all over it. Is there any code that I
can do to make
access not open the report display a message box stating that the
criteria
they have entered does not give any records ?

thanx,



Allen Browne said:
The quotes are not in the right place.
You must use square brackets around the field name that contains a space.
If the number field is Null, the string will be malformed, so use Nz().
Bracketing can also help.

Try:

strWhere = "(Recruitment ID = """ & Me.[ID_Combo] & _
""") And (Recruitment_Counter = " & Nz(Me.[Counter_Combo],0) & _
") And ([Position Title] = """ & Me.[Position_Combo] & """)"

Immediately after that line, add:
Debug.Print strWhere

If it fails, open the Immediate Window (Ctrl+G) and look at what was printed
there. See if the quotes and brackets match, the ANDs turn up in the right
places, etc. It must look like the WHERE clause of a query. This is
invaluable for seeing what's wrong, so you can figure out how to fix it.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

HelloWorld said:
Ok I am trying to implement the strwhere in my report but seem to be
having a
problem.

Here is my code
#####################################################
Private Sub OK_Click()
Dim strWhere As String
strWhere = "Recruitment ID = """ & Me.[ID_Combo] & """" And
"Recruitment_Counter = & Me.[Counter_Combo]"
And "Position Title = """ & Me.[Position_Combo] & """"
DoCmd.OpenReport "[Report_List]", acViewPreview, , strWhere

DoCmd.OpenReport "Report2", acViewPreview, , strWhere

End Sub

#####################################################

I am getting a type mismatch error # 13 when i try to run the report.

the datatypes of the fields are

Recruitment ID - Text
Recruitment_Counter - Number
Position Title - Text

Can you tell me what I am doing wrong ?



Allen Browne said:
Corrrect. When you use the WhereCondition of OpenReport, you no longer
need
the parameters in the query.

If you want your original form to open the form for entering the
parameters,
just use:
Docmd.OpenForm "MyParameterForm"
Then on MyParameterForm, put Ok and Cancel buttons. The Cancel just
closes
it. The Click event of the Ok button is the code suggested in the
previous
reply.

To ask the user about opening Report2 as well:
If MsgBox("Report2 also?", vbYesNo) = vbyes Then
DoCmd.OpenReport "Report2", acViewPreview, , strWhere
End If

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

So Do I not need any parameters for the queries the reports are based
on ?

Also - is there any way to make the form to open off of the same
buttons
cick event ?


:

Use a form where the user can enter the parameters for the report.
Then
when
they click the button, both reports can read the text boxes on the
report
for their parameters.

The Click event procedure for your command button will end up like
this:

Private Sub cmdPrint_Click()
Dim strWhere As String
strWhere = "City = """ & Me.[City] & """"
DoCmd.OpenReport "Report1", acViewPreview, , strWhere
DoCmd.OpenReport "Report2", acViewPreview, , strWhere
End Sub

Some examples of how to build the WhereCondition:

a) Just based on the primary key value:
http://allenbrowne.com/casu-15.html

b) Based on a date range:
http://allenbrowne.com/casu-07.html

c) Based on a whole bunch of different controls that might or might
not
have
any value entered:
http://allenbrowne.com/unlinked/Search2000.zip

The last one is a downloadable database (Access 2000 or later) without
an
explanatory article.

I am to get multiple reports to run off of a single onClick event.

I have letters that are made into reports and i also have another
report
that would print out the envelopes for those records.

I need to code something that would launch the first report (for
printing)
and then lauch a message box to confirm the launching of the second
report.

I have the following questions -

1 How do I pass the recordset produced by the first reports query to
the
second report without making the user re-enter all the parameters.
I
need
the letters to match the envelopes of course.

2. How Do I make the MsgBox that is used to confirm / deny the
opening
of
the second report.


please advise and if it is too vauge what I have typed - please let
me
know
and I will try to explain myself better.

-oh and why not do this with a Word mail merge? - the company dosent
have
liscence for word - they use some proprietary word processing
software -
but
they have access for Databases - go figure.
 
A

Allen Browne

The simplest solution is to cancel the report's NoData event, so that it
does not open if it has no data.

The #Error occurs in any calculated control when there is no data. You can
avoid it by changing the calculated controls so they test the report's
HasData property.

For example, if you have a text box with Contol Source of:
=Sum([Amount])
change it to:
=IIf([Report].[HasData], Sum([Amount]), 0)
 

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