VBA with Access help?

G

Guest

I have a command button set up to print a report. The cmd button is attached
to the following code:
Private Sub cmdPrintRecord_Click()

Dim strReportName As String
Dim byteCriteria As String

strReportName = "SvrReq Work Order"
strCriteria = "[Request_Tracking_ID]=" & Me![Request_Tracking_ID]
' DoCmd.OpenReport strReportName, acViewPreview, , byteCriteria

DoCmd.OpenReport strReportName, acViewPrint, , byteCriteria


End Sub

The report SvrReq Work Order is based on a parameter query. When you click
the button and get the input box and input your data and click ok the report
prints but I keep getting the "Microsoft Access has encountered a problem and
needs to close....blah, blah, blah" I can't figure out why it keeps doing
this. Any suggestions?
 
J

Jeff Boyce

I see
Dim byteCriteria as String

and wonder why variable typed as "String" has a name suggesting "byte"
data.

I see
strCriteria being set to some value, but never having been Dim'd

(which tells me you don't have Option Explicit set on, or you'd get a
compile error on this.)

I see an OpenReport action that uses byteCriteria as a value in the syntax,
but no value has ever been set.

I'm guessing you need to turn on Option Explicit -- it would have caught
this right away!

Good luck

Jeff Boyce
<Access MVP>
 
G

Guest

Jeff, I need you to be a little more clear. I somewhat understand what you
are saying. The reports are built on a parameter query and I can't remember
how I got to that byte criteria. However this print problem is hosing up my
db. Do you need more information and can you help me?

Jeff Boyce said:
I see
Dim byteCriteria as String

and wonder why variable typed as "String" has a name suggesting "byte"
data.

I see
strCriteria being set to some value, but never having been Dim'd

(which tells me you don't have Option Explicit set on, or you'd get a
compile error on this.)

I see an OpenReport action that uses byteCriteria as a value in the syntax,
but no value has ever been set.

I'm guessing you need to turn on Option Explicit -- it would have caught
this right away!

Good luck

Jeff Boyce
<Access MVP>

I have a command button set up to print a report. The cmd button is attached
to the following code:
Private Sub cmdPrintRecord_Click()

Dim strReportName As String
Dim byteCriteria As String

strReportName = "SvrReq Work Order"
strCriteria = "[Request_Tracking_ID]=" & Me![Request_Tracking_ID]
' DoCmd.OpenReport strReportName, acViewPreview, , byteCriteria

DoCmd.OpenReport strReportName, acViewPrint, , byteCriteria


End Sub

The report SvrReq Work Order is based on a parameter query. When you click
the button and get the input box and input your data and click ok the report
prints but I keep getting the "Microsoft Access has encountered a problem and
needs to close....blah, blah, blah" I can't figure out why it keeps doing
this. Any suggestions?
 
J

Jeff Boyce

I'm not sure how to be much clearer.

You are using a variable that hasn't been defined (strCriteria).

You are using a variable that hasn't had a value set (byteCriteria).

Unless you decide on one, define it AND set a value, I don't see how your
OpenReport syntax could work...

--
Good luck

Jeff Boyce
<Access MVP>

Jeff, I need you to be a little more clear. I somewhat understand what you
are saying. The reports are built on a parameter query and I can't remember
how I got to that byte criteria. However this print problem is hosing up my
db. Do you need more information and can you help me?

Jeff Boyce said:
I see
Dim byteCriteria as String

and wonder why variable typed as "String" has a name suggesting "byte"
data.

I see
strCriteria being set to some value, but never having been Dim'd

(which tells me you don't have Option Explicit set on, or you'd get a
compile error on this.)

I see an OpenReport action that uses byteCriteria as a value in the syntax,
but no value has ever been set.

I'm guessing you need to turn on Option Explicit -- it would have caught
this right away!

Good luck

Jeff Boyce
<Access MVP>

in message news:[email protected]...
I have a command button set up to print a report. The cmd button is attached
to the following code:
Private Sub cmdPrintRecord_Click()

Dim strReportName As String
Dim byteCriteria As String

strReportName = "SvrReq Work Order"
strCriteria = "[Request_Tracking_ID]=" & Me![Request_Tracking_ID]
' DoCmd.OpenReport strReportName, acViewPreview, , byteCriteria

DoCmd.OpenReport strReportName, acViewPrint, , byteCriteria


End Sub

The report SvrReq Work Order is based on a parameter query. When you click
the button and get the input box and input your data and click ok the report
prints but I keep getting the "Microsoft Access has encountered a
problem
and
needs to close....blah, blah, blah" I can't figure out why it keeps doing
this. Any suggestions?
 
G

Guest

Jeff thank you. I looked at a similar code and realized I made an error.
But can you riddle me this. I have two VBA codes that do primarily the same
thing. Please let me explain. On my data entry form I have two print
buttons that print two different reports. Both reports are tied to parameter
queries. On clicking a button an input box appears requiring an id number to
be added. Upon clicking ok the report goes directly to the printer. The vba
codes for this are identical except for the report name. Below are the two
codes.
Private Sub cmdPrintQCCRecord_Click()

Dim strReportName As String
Dim Criteria As String

strReportName = "test1 - rptQCC"
strCriteria = "[Request_Tracking_ID]=" & Me![Request_Tracking_ID]
DoCmd.OpenReport strReportName, acViewPrint, , Criteria


End Sub

Private Sub cmdPrintRecord_Click()

Dim strReportName As String
Dim strCriteria As String

strReportName = "SvrReq Work Order"
strCriteria = "[Request_Tracking_ID]=" & Me![Request_Tracking_ID]

DoCmd.OpenReport strReportName, acViewPrint, , Criteria

End Sub

Now when I use the cmdPrintQCCRecord Click code it works fine. However when
I use the cmdPrintRecord Click code the report prints but I get the dreaded
"Microsoft Access has encountered a problem and needs to close....blah, blah,
blah" I can't figure out why it keeps doing this.

Please forgive me I'm not trying to be difficult, perhaps I wasn't quite as
clear as I should have been. I am just frustrated that I can't figure this
out.

Jeff Boyce said:
I'm not sure how to be much clearer.

You are using a variable that hasn't been defined (strCriteria).

You are using a variable that hasn't had a value set (byteCriteria).

Unless you decide on one, define it AND set a value, I don't see how your
OpenReport syntax could work...

--
Good luck

Jeff Boyce
<Access MVP>

Jeff, I need you to be a little more clear. I somewhat understand what you
are saying. The reports are built on a parameter query and I can't remember
how I got to that byte criteria. However this print problem is hosing up my
db. Do you need more information and can you help me?

Jeff Boyce said:
I see
Dim byteCriteria as String

and wonder why variable typed as "String" has a name suggesting "byte"
data.

I see
strCriteria being set to some value, but never having been Dim'd

(which tells me you don't have Option Explicit set on, or you'd get a
compile error on this.)

I see an OpenReport action that uses byteCriteria as a value in the syntax,
but no value has ever been set.

I'm guessing you need to turn on Option Explicit -- it would have caught
this right away!

Good luck

Jeff Boyce
<Access MVP>

in message I have a command button set up to print a report. The cmd button is
attached
to the following code:
Private Sub cmdPrintRecord_Click()

Dim strReportName As String
Dim byteCriteria As String

strReportName = "SvrReq Work Order"
strCriteria = "[Request_Tracking_ID]=" & Me![Request_Tracking_ID]
' DoCmd.OpenReport strReportName, acViewPreview, , byteCriteria

DoCmd.OpenReport strReportName, acViewPrint, , byteCriteria


End Sub

The report SvrReq Work Order is based on a parameter query. When you
click
the button and get the input box and input your data and click ok the
report
prints but I keep getting the "Microsoft Access has encountered a problem
and
needs to close....blah, blah, blah" I can't figure out why it keeps doing
this. Any suggestions?
 
J

Jeff Boyce

They are not identical. Once again, I STRONGLY urge you to set Option
Explicit before doing any more code. Your second subroutine dim's
strCriteria, but the related OpenReport refers to "Criteria".

Using Option Explicit for ALL your code would have caught this, just as it
would have caught your earlier spelling issues.

--
Good luck

Jeff Boyce
<Access MVP>

Jeff thank you. I looked at a similar code and realized I made an error.
But can you riddle me this. I have two VBA codes that do primarily the same
thing. Please let me explain. On my data entry form I have two print
buttons that print two different reports. Both reports are tied to parameter
queries. On clicking a button an input box appears requiring an id number to
be added. Upon clicking ok the report goes directly to the printer. The vba
codes for this are identical except for the report name. Below are the two
codes.
Private Sub cmdPrintQCCRecord_Click()

Dim strReportName As String
Dim Criteria As String

strReportName = "test1 - rptQCC"
strCriteria = "[Request_Tracking_ID]=" & Me![Request_Tracking_ID]
DoCmd.OpenReport strReportName, acViewPrint, , Criteria


End Sub

Private Sub cmdPrintRecord_Click()

Dim strReportName As String
Dim strCriteria As String

strReportName = "SvrReq Work Order"
strCriteria = "[Request_Tracking_ID]=" & Me![Request_Tracking_ID]

DoCmd.OpenReport strReportName, acViewPrint, , Criteria

End Sub

Now when I use the cmdPrintQCCRecord Click code it works fine. However when
I use the cmdPrintRecord Click code the report prints but I get the dreaded
"Microsoft Access has encountered a problem and needs to close....blah, blah,
blah" I can't figure out why it keeps doing this.

Please forgive me I'm not trying to be difficult, perhaps I wasn't quite as
clear as I should have been. I am just frustrated that I can't figure this
out.

Jeff Boyce said:
I'm not sure how to be much clearer.

You are using a variable that hasn't been defined (strCriteria).

You are using a variable that hasn't had a value set (byteCriteria).

Unless you decide on one, define it AND set a value, I don't see how your
OpenReport syntax could work...

--
Good luck

Jeff Boyce
<Access MVP>

in message news:[email protected]... what
you up
my
wrote
in message I have a command button set up to print a report. The cmd button is
attached
to the following code:
Private Sub cmdPrintRecord_Click()

Dim strReportName As String
Dim byteCriteria As String

strReportName = "SvrReq Work Order"
strCriteria = "[Request_Tracking_ID]=" & Me![Request_Tracking_ID]
' DoCmd.OpenReport strReportName, acViewPreview, , byteCriteria

DoCmd.OpenReport strReportName, acViewPrint, , byteCriteria


End Sub

The report SvrReq Work Order is based on a parameter query. When you
click
the button and get the input box and input your data and click ok the
report
prints but I keep getting the "Microsoft Access has encountered a problem
and
needs to close....blah, blah, blah" I can't figure out why it
keeps
doing
this. Any suggestions?
 

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