Command Button Question

A

ADB_Seeker

I searched through current posts and didn't find one that addressed my
specific issue and am hoping someone can help. I am an Access beginner so
please give specific steps and information (thanks).
I created a form that has a command button named Preview Report. This
button is supposed to display the form that is on the screen, which contains
new data.
When I click the button, it asks for the ER Number, which I input, but it
displays a blank report and not the current information in the form.
I have to save the data, exit the form, open it again, click on the
Preview Report, and enter the ER Number (a field on the form) before the
report displays the content.
What I need the Preview Report command button to do is show the current
information on the screen plus not ask for the ER Number. Following is the
code I use in the Event Procedure. Thank you in advance for your assistance.
LT

Private Sub Command114_Click()
On Error GoTo Err_Command114_Click

Dim stDocName As String

stDocName = "ER FIND REPORT"
DoCmd.OpenReport stDocName, acPreview

Exit_Command114_Click:
Exit Sub

Err_Command114_Click:
MsgBox Err.Description
Resume Exit_Command114_Click

End Sub
 
F

fredg

I searched through current posts and didn't find one that addressed my
specific issue and am hoping someone can help. I am an Access beginner so
please give specific steps and information (thanks).
I created a form that has a command button named Preview Report. This
button is supposed to display the form that is on the screen, which contains
new data.
When I click the button, it asks for the ER Number, which I input, but it
displays a blank report and not the current information in the form.
I have to save the data, exit the form, open it again, click on the
Preview Report, and enter the ER Number (a field on the form) before the
report displays the content.
What I need the Preview Report command button to do is show the current
information on the screen plus not ask for the ER Number. Following is the
code I use in the Event Procedure. Thank you in advance for your assistance.
LT

Private Sub Command114_Click()
On Error GoTo Err_Command114_Click

Dim stDocName As String

stDocName = "ER FIND REPORT"
DoCmd.OpenReport stDocName, acPreview

Exit_Command114_Click:
Exit Sub

Err_Command114_Click:
MsgBox Err.Description
Resume Exit_Command114_Click

End Sub

So this is a new record you are entering and you wish to open a report
based upon the ER Number of the record currently displayed on the
form. Watch your terminology.... you are opening a report, not
"display(ing) the form that is on the screen".
There is nothing in your code to tell Access which record to display.
Look up the OpenReport method in VBA help files. You will find there
is a Where argument. That is how you tell Access what records to
display in the report.

Try it this way. If [ERNumber] is a Number datatype:

Private Sub Command114_Click()

On Error GoTo Err_Command114_Click
DoCmd.RunCommand acCmdSaveRecord
Dim stDocName As String
stDocName = "ER FIND REPORT"
DoCmd.OpenReport stDocName, acPreview, , "[ERNumber] = " &
Me.[ERNumber]
Exit_Command114_Click:
Exit Sub
Err_Command114_Click:
MsgBox Err.Description
Resume Exit_Command114_Click

End Sub

However, if [ERNumber] is a Text datatype field, then use:
DoCmd.OpenReport stDocName, acPreview, , "[ERNumber] = '" &
Me.[ERNumber] & "'"

Note that I added code (DoCmd.RunCommand ...) to explicitly save the
record before opening the report.
 
A

ADB_Seeker

Thank you for the help with terminology. The code you gave worked perfectly.
I appreciate your help.

fredg said:
I searched through current posts and didn't find one that addressed my
specific issue and am hoping someone can help. I am an Access beginner so
please give specific steps and information (thanks).
I created a form that has a command button named Preview Report. This
button is supposed to display the form that is on the screen, which contains
new data.
When I click the button, it asks for the ER Number, which I input, but it
displays a blank report and not the current information in the form.
I have to save the data, exit the form, open it again, click on the
Preview Report, and enter the ER Number (a field on the form) before the
report displays the content.
What I need the Preview Report command button to do is show the current
information on the screen plus not ask for the ER Number. Following is the
code I use in the Event Procedure. Thank you in advance for your assistance.
LT

Private Sub Command114_Click()
On Error GoTo Err_Command114_Click

Dim stDocName As String

stDocName = "ER FIND REPORT"
DoCmd.OpenReport stDocName, acPreview

Exit_Command114_Click:
Exit Sub

Err_Command114_Click:
MsgBox Err.Description
Resume Exit_Command114_Click

End Sub

So this is a new record you are entering and you wish to open a report
based upon the ER Number of the record currently displayed on the
form. Watch your terminology.... you are opening a report, not
"display(ing) the form that is on the screen".
There is nothing in your code to tell Access which record to display.
Look up the OpenReport method in VBA help files. You will find there
is a Where argument. That is how you tell Access what records to
display in the report.

Try it this way. If [ERNumber] is a Number datatype:

Private Sub Command114_Click()

On Error GoTo Err_Command114_Click
DoCmd.RunCommand acCmdSaveRecord
Dim stDocName As String
stDocName = "ER FIND REPORT"
DoCmd.OpenReport stDocName, acPreview, , "[ERNumber] = " &
Me.[ERNumber]
Exit_Command114_Click:
Exit Sub
Err_Command114_Click:
MsgBox Err.Description
Resume Exit_Command114_Click

End Sub

However, if [ERNumber] is a Text datatype field, then use:
DoCmd.OpenReport stDocName, acPreview, , "[ERNumber] = '" &
Me.[ERNumber] & "'"

Note that I added code (DoCmd.RunCommand ...) to explicitly save the
record before opening the report.
 

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