Print report for record on data entry form

V

Veus

Hi,

I have a data entry form which has a submit button.
When a user clicks this submit button i need the form to open a report
with the newly entered data and close the form.
This is what ive got so far:

Me.Dirty = False

Dim strReportName As String
Dim strCriteria As String

strReportName = "bookingLetter"
strCriteria = "[bookingsID]= " & Me.ID & ""
'DoCmd.Close
DoCmd.OpenReport strReportName, acViewPreview, , strCriteria

The error is that the report comes up blank, the report actually
appears but the fields show '#Error', i assume this is because the data
on the form isnt being saved before the report opens (so Me.ID isnt in
the database yet, hence no records)

As you can see i have tried to get round this by forcing a save
(Me.Dirty = False) as well as closing the form before opening the
report.
I have also tried placing the open report code in the Form_AfterUpdate
function however it is the same.
Can anyone shed any light on this?
 
A

Allen Browne

The code looks like you are on the right track.

Is the record visible in the form when you run this?
Or has the form moved to a new record?

Do you have a control named ID on your form?
What is the Control Source of this text box?

What is the Data type of the field it is bound to?
If it is a Number field, omit the quotes at the end, i.e.:
strCriteria = "[bookingsID]= " & Me.ID
If it is a Text field, you need extra quotes:
strCriteria = "[bookingsID]= """ & Me.ID & """"
Explanation of the quotes at:
http://allenbrowne.com/casu-17.html

Stil stuck? After the line starting "strCriteria = ", add:
Debug.Print strCriteria
When it fails, open the Immediate Window (Ctrl+G), and look at what came
out.
 
V

Veus

Is the record visible in the form when you run this?
Or has the form moved to a new record?

Form is visible
Do you have a control named ID on your form?
What is the Control Source of this text box?

Yes i do. The ID control is populated once the record is saved (i click
on another section of the form to make sure)
The control source is: ID

The data type is a number and have removed the quotes as you suggested
however no change.

The debug.Print statement returns:
[bookingsID]= 71235

I have tried manually entering a booking which is in the database and
it shows the correct report.
Its just it doesnt appear from the DataEntry form.



Allen said:
The code looks like you are on the right track.

Is the record visible in the form when you run this?
Or has the form moved to a new record?

Do you have a control named ID on your form?
What is the Control Source of this text box?

What is the Data type of the field it is bound to?
If it is a Number field, omit the quotes at the end, i.e.:
strCriteria = "[bookingsID]= " & Me.ID
If it is a Text field, you need extra quotes:
strCriteria = "[bookingsID]= """ & Me.ID & """"
Explanation of the quotes at:
http://allenbrowne.com/casu-17.html

Stil stuck? After the line starting "strCriteria = ", add:
Debug.Print strCriteria
When it fails, open the Immediate Window (Ctrl+G), and look at what came
out.

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

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

Veus said:
I have a data entry form which has a submit button.
When a user clicks this submit button i need the form to open a report
with the newly entered data and close the form.
This is what ive got so far:

Me.Dirty = False

Dim strReportName As String
Dim strCriteria As String

strReportName = "bookingLetter"
strCriteria = "[bookingsID]= " & Me.ID & ""
'DoCmd.Close
DoCmd.OpenReport strReportName, acViewPreview, , strCriteria

The error is that the report comes up blank, the report actually
appears but the fields show '#Error', i assume this is because the data
on the form isnt being saved before the report opens (so Me.ID isnt in
the database yet, hence no records)

As you can see i have tried to get round this by forcing a save
(Me.Dirty = False) as well as closing the form before opening the
report.
I have also tried placing the open report code in the Form_AfterUpdate
function however it is the same.
Can anyone shed any light on this?
 
V

Veus

Hmm.

I think ive solved it. For some strange reason reports made on bookings
other than the last few worked. The recent ones didnt. I think its to
do with the way i changed things but forgot to refresh the tables, im
using linked tables.

Thanks for your help :)
Veus said:
Is the record visible in the form when you run this?
Or has the form moved to a new record?

Form is visible
Do you have a control named ID on your form?
What is the Control Source of this text box?

Yes i do. The ID control is populated once the record is saved (i click
on another section of the form to make sure)
The control source is: ID

The data type is a number and have removed the quotes as you suggested
however no change.

The debug.Print statement returns:
[bookingsID]= 71235

I have tried manually entering a booking which is in the database and
it shows the correct report.
Its just it doesnt appear from the DataEntry form.



Allen said:
The code looks like you are on the right track.

Is the record visible in the form when you run this?
Or has the form moved to a new record?

Do you have a control named ID on your form?
What is the Control Source of this text box?

What is the Data type of the field it is bound to?
If it is a Number field, omit the quotes at the end, i.e.:
strCriteria = "[bookingsID]= " & Me.ID
If it is a Text field, you need extra quotes:
strCriteria = "[bookingsID]= """ & Me.ID & """"
Explanation of the quotes at:
http://allenbrowne.com/casu-17.html

Stil stuck? After the line starting "strCriteria = ", add:
Debug.Print strCriteria
When it fails, open the Immediate Window (Ctrl+G), and look at what came
out.

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

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

Veus said:
I have a data entry form which has a submit button.
When a user clicks this submit button i need the form to open a report
with the newly entered data and close the form.
This is what ive got so far:

Me.Dirty = False

Dim strReportName As String
Dim strCriteria As String

strReportName = "bookingLetter"
strCriteria = "[bookingsID]= " & Me.ID & ""
'DoCmd.Close
DoCmd.OpenReport strReportName, acViewPreview, , strCriteria

The error is that the report comes up blank, the report actually
appears but the fields show '#Error', i assume this is because the data
on the form isnt being saved before the report opens (so Me.ID isnt in
the database yet, hence no records)

As you can see i have tried to get round this by forcing a save
(Me.Dirty = False) as well as closing the form before opening the
report.
I have also tried placing the open report code in the Form_AfterUpdate
function however it is the same.
Can anyone shed any light on this?
 
A

Allen Browne

It doesn't appear in the data entry form?

From topic, I take it the record *does* appear in the form, but doesn't show
up in the report. Can you clarify?

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

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

Veus said:
Is the record visible in the form when you run this?
Or has the form moved to a new record?

Form is visible
Do you have a control named ID on your form?
What is the Control Source of this text box?

Yes i do. The ID control is populated once the record is saved (i click
on another section of the form to make sure)
The control source is: ID

The data type is a number and have removed the quotes as you suggested
however no change.

The debug.Print statement returns:
[bookingsID]= 71235

I have tried manually entering a booking which is in the database and
it shows the correct report.
Its just it doesnt appear from the DataEntry form.



Allen said:
The code looks like you are on the right track.

Is the record visible in the form when you run this?
Or has the form moved to a new record?

Do you have a control named ID on your form?
What is the Control Source of this text box?

What is the Data type of the field it is bound to?
If it is a Number field, omit the quotes at the end, i.e.:
strCriteria = "[bookingsID]= " & Me.ID
If it is a Text field, you need extra quotes:
strCriteria = "[bookingsID]= """ & Me.ID & """"
Explanation of the quotes at:
http://allenbrowne.com/casu-17.html

Stil stuck? After the line starting "strCriteria = ", add:
Debug.Print strCriteria
When it fails, open the Immediate Window (Ctrl+G), and look at what came
out.

Veus said:
I have a data entry form which has a submit button.
When a user clicks this submit button i need the form to open a report
with the newly entered data and close the form.
This is what ive got so far:

Me.Dirty = False

Dim strReportName As String
Dim strCriteria As String

strReportName = "bookingLetter"
strCriteria = "[bookingsID]= " & Me.ID & ""
'DoCmd.Close
DoCmd.OpenReport strReportName, acViewPreview, , strCriteria

The error is that the report comes up blank, the report actually
appears but the fields show '#Error', i assume this is because the data
on the form isnt being saved before the report opens (so Me.ID isnt in
the database yet, hence no records)

As you can see i have tried to get round this by forcing a save
(Me.Dirty = False) as well as closing the form before opening the
report.
I have also tried placing the open report code in the Form_AfterUpdate
function however it is the same.
Can anyone shed any light on this?
 

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