Problem with selecting the right report based on data

G

Guest

I am trying to figure out how to add a button to a form that will print two
different reports based on the record data. The field values are either C or
D (the ones I am concerned with), I have confirmed the field Type is text.
Both reports can be printed using a seperate print function, but I would much
rather take the human error out of the problem.

Private Sub btnLayout_Click()
On Error GoTo Err_btnLayout_Click
Dim stDocName As String
Dim stDocName1 As String
stDocName = "rptLabel03"
stDocName1 = "rptLabel02"

If Me.Type = "C" Or Me.Type = "D" Then
DoCmd.OpenReport stDocName, acNormal, , Me.OpenArgs
Else
DoCmd.OpenReport stDocName1, acNormal, , Me.OpenArgs
End If
DoCmd.Close acForm, "frmLabelSel"

Exit_btnLayout_Click:
Exit Sub

Err_btnLayout_Click:
MsgBox Err.Description
Resume Exit_btnLayout_Click

Every change I have tried to make, I get the second report, not the first.
Help?!
 
G

Guest

The way you have it coded, it will always print out the first report.
Since your values can only be C or D, this statement is always true
If Me.Type = "C" Or Me.Type = "D" Then

Here is how I would do it:

Private Sub btnLayout_Click()
Dim strDocName As String
Const conLabel03 As String = "rptLabel03"
Const conLabel02 As String = "rptLabel02"

On Error GoTo Err_btnLayout_Click

Select Case Me.Type
Case "C"
strDocName = conLabel03
Case "D"
strDocName = conLabel02
Case Else
MsgBox "Invalid Value in Type"
Me.Type.SetFocus
Exit Sub
End Select

DoCmd.OpenReport strDocName, acNormal, , Me.OpenArgs

DoCmd.Close acForm, "frmLabelSel"

Exit_btnLayout_Click:
Exit Sub

Err_btnLayout_Click:
MsgBox Err.Description
Resume Exit_btnLayout_Click
End Sub


One other issue. I see you have a control named Type. You should not use
Type as a name. It is an Access reserved word. No Access reserved words
should be used as names. It can confuse Access. If you can't change the
name, then enclose it in brackets Me.[Type]
Most of the time that will avoid a problem, but not always.
 
G

Guest

Ok, I see where you are going here, I may have been a bit unclear, I only
want a specific report used if the data is C or D, if else, then print the
other report. I think I can just replace the error message you put in with
the other label. More like:

Select Case Me.Type
Case "C"
strDocName = conLabel03
Case "D"
strDocName = conLabel03
Case Else
strDocName = conlabel02



Klatuu said:
The way you have it coded, it will always print out the first report.
Since your values can only be C or D, this statement is always true
If Me.Type = "C" Or Me.Type = "D" Then

Here is how I would do it:

Private Sub btnLayout_Click()
Dim strDocName As String
Const conLabel03 As String = "rptLabel03"
Const conLabel02 As String = "rptLabel02"

On Error GoTo Err_btnLayout_Click

Select Case Me.Type
Case "C"
strDocName = conLabel03
Case "D"
strDocName = conLabel02
Case Else
MsgBox "Invalid Value in Type"
Me.Type.SetFocus
Exit Sub
End Select

DoCmd.OpenReport strDocName, acNormal, , Me.OpenArgs

DoCmd.Close acForm, "frmLabelSel"

Exit_btnLayout_Click:
Exit Sub

Err_btnLayout_Click:
MsgBox Err.Description
Resume Exit_btnLayout_Click
End Sub


One other issue. I see you have a control named Type. You should not use
Type as a name. It is an Access reserved word. No Access reserved words
should be used as names. It can confuse Access. If you can't change the
name, then enclose it in brackets Me.[Type]
Most of the time that will avoid a problem, but not always.
--
Dave Hargis, Microsoft Access MVP


David Pelizzari said:
I am trying to figure out how to add a button to a form that will print two
different reports based on the record data. The field values are either C or
D (the ones I am concerned with), I have confirmed the field Type is text.
Both reports can be printed using a seperate print function, but I would much
rather take the human error out of the problem.

Private Sub btnLayout_Click()
On Error GoTo Err_btnLayout_Click
Dim stDocName As String
Dim stDocName1 As String
stDocName = "rptLabel03"
stDocName1 = "rptLabel02"

If Me.Type = "C" Or Me.Type = "D" Then
DoCmd.OpenReport stDocName, acNormal, , Me.OpenArgs
Else
DoCmd.OpenReport stDocName1, acNormal, , Me.OpenArgs
End If
DoCmd.Close acForm, "frmLabelSel"

Exit_btnLayout_Click:
Exit Sub

Err_btnLayout_Click:
MsgBox Err.Description
Resume Exit_btnLayout_Click

Every change I have tried to make, I get the second report, not the first.
Help?!
 
G

Guest

That would work
--
Dave Hargis, Microsoft Access MVP


David Pelizzari said:
Ok, I see where you are going here, I may have been a bit unclear, I only
want a specific report used if the data is C or D, if else, then print the
other report. I think I can just replace the error message you put in with
the other label. More like:

Select Case Me.Type
Case "C"
strDocName = conLabel03
Case "D"
strDocName = conLabel03
Case Else
strDocName = conlabel02



Klatuu said:
The way you have it coded, it will always print out the first report.
Since your values can only be C or D, this statement is always true
If Me.Type = "C" Or Me.Type = "D" Then

Here is how I would do it:

Private Sub btnLayout_Click()
Dim strDocName As String
Const conLabel03 As String = "rptLabel03"
Const conLabel02 As String = "rptLabel02"

On Error GoTo Err_btnLayout_Click

Select Case Me.Type
Case "C"
strDocName = conLabel03
Case "D"
strDocName = conLabel02
Case Else
MsgBox "Invalid Value in Type"
Me.Type.SetFocus
Exit Sub
End Select

DoCmd.OpenReport strDocName, acNormal, , Me.OpenArgs

DoCmd.Close acForm, "frmLabelSel"

Exit_btnLayout_Click:
Exit Sub

Err_btnLayout_Click:
MsgBox Err.Description
Resume Exit_btnLayout_Click
End Sub


One other issue. I see you have a control named Type. You should not use
Type as a name. It is an Access reserved word. No Access reserved words
should be used as names. It can confuse Access. If you can't change the
name, then enclose it in brackets Me.[Type]
Most of the time that will avoid a problem, but not always.
--
Dave Hargis, Microsoft Access MVP


David Pelizzari said:
I am trying to figure out how to add a button to a form that will print two
different reports based on the record data. The field values are either C or
D (the ones I am concerned with), I have confirmed the field Type is text.
Both reports can be printed using a seperate print function, but I would much
rather take the human error out of the problem.

Private Sub btnLayout_Click()
On Error GoTo Err_btnLayout_Click
Dim stDocName As String
Dim stDocName1 As String
stDocName = "rptLabel03"
stDocName1 = "rptLabel02"

If Me.Type = "C" Or Me.Type = "D" Then
DoCmd.OpenReport stDocName, acNormal, , Me.OpenArgs
Else
DoCmd.OpenReport stDocName1, acNormal, , Me.OpenArgs
End If
DoCmd.Close acForm, "frmLabelSel"

Exit_btnLayout_Click:
Exit Sub

Err_btnLayout_Click:
MsgBox Err.Description
Resume Exit_btnLayout_Click

Every change I have tried to make, I get the second report, not the first.
Help?!
 
G

George Nicholson

Consider:

Select Case NZ(Me.Type,"")
Case ""
MsgBox "Please select a Type"
Me.Type.SetFocus
Exit Sub
Case "C", "D"
strDocName = conLabel03
Case Else
strDocName = conlabel02
End Select




David Pelizzari said:
Ok, I see where you are going here, I may have been a bit unclear, I only
want a specific report used if the data is C or D, if else, then print the
other report. I think I can just replace the error message you put in
with
the other label. More like:

Select Case Me.Type
Case "C"
strDocName = conLabel03
Case "D"
strDocName = conLabel03
Case Else
strDocName = conlabel02



Klatuu said:
The way you have it coded, it will always print out the first report.
Since your values can only be C or D, this statement is always true
If Me.Type = "C" Or Me.Type = "D" Then

Here is how I would do it:

Private Sub btnLayout_Click()
Dim strDocName As String
Const conLabel03 As String = "rptLabel03"
Const conLabel02 As String = "rptLabel02"

On Error GoTo Err_btnLayout_Click

Select Case Me.Type
Case "C"
strDocName = conLabel03
Case "D"
strDocName = conLabel02
Case Else
MsgBox "Invalid Value in Type"
Me.Type.SetFocus
Exit Sub
End Select

DoCmd.OpenReport strDocName, acNormal, , Me.OpenArgs

DoCmd.Close acForm, "frmLabelSel"

Exit_btnLayout_Click:
Exit Sub

Err_btnLayout_Click:
MsgBox Err.Description
Resume Exit_btnLayout_Click
End Sub


One other issue. I see you have a control named Type. You should not
use
Type as a name. It is an Access reserved word. No Access reserved words
should be used as names. It can confuse Access. If you can't change the
name, then enclose it in brackets Me.[Type]
Most of the time that will avoid a problem, but not always.
--
Dave Hargis, Microsoft Access MVP


David Pelizzari said:
I am trying to figure out how to add a button to a form that will print
two
different reports based on the record data. The field values are
either C or
D (the ones I am concerned with), I have confirmed the field Type is
text.
Both reports can be printed using a seperate print function, but I
would much
rather take the human error out of the problem.

Private Sub btnLayout_Click()
On Error GoTo Err_btnLayout_Click
Dim stDocName As String
Dim stDocName1 As String
stDocName = "rptLabel03"
stDocName1 = "rptLabel02"

If Me.Type = "C" Or Me.Type = "D" Then
DoCmd.OpenReport stDocName, acNormal, , Me.OpenArgs
Else
DoCmd.OpenReport stDocName1, acNormal, , Me.OpenArgs
End If
DoCmd.Close acForm, "frmLabelSel"

Exit_btnLayout_Click:
Exit Sub

Err_btnLayout_Click:
MsgBox Err.Description
Resume Exit_btnLayout_Click

Every change I have tried to make, I get the second report, not the
first.
Help?!
 
G

Guest

Well, it is progress, the logic almost works. When I select a record and go
to print, no matter what the data is, I get rptlabel02... I checked the
table again, the field Type is set to text, and the characters are all
uppercase.

Klatuu said:
That would work
--
Dave Hargis, Microsoft Access MVP


David Pelizzari said:
Ok, I see where you are going here, I may have been a bit unclear, I only
want a specific report used if the data is C or D, if else, then print the
other report. I think I can just replace the error message you put in with
the other label. More like:

Select Case Me.Type
Case "C"
strDocName = conLabel03
Case "D"
strDocName = conLabel03
Case Else
strDocName = conlabel02



Klatuu said:
The way you have it coded, it will always print out the first report.
Since your values can only be C or D, this statement is always true
If Me.Type = "C" Or Me.Type = "D" Then

Here is how I would do it:

Private Sub btnLayout_Click()
Dim strDocName As String
Const conLabel03 As String = "rptLabel03"
Const conLabel02 As String = "rptLabel02"

On Error GoTo Err_btnLayout_Click

Select Case Me.Type
Case "C"
strDocName = conLabel03
Case "D"
strDocName = conLabel02
Case Else
MsgBox "Invalid Value in Type"
Me.Type.SetFocus
Exit Sub
End Select

DoCmd.OpenReport strDocName, acNormal, , Me.OpenArgs

DoCmd.Close acForm, "frmLabelSel"

Exit_btnLayout_Click:
Exit Sub

Err_btnLayout_Click:
MsgBox Err.Description
Resume Exit_btnLayout_Click
End Sub


One other issue. I see you have a control named Type. You should not use
Type as a name. It is an Access reserved word. No Access reserved words
should be used as names. It can confuse Access. If you can't change the
name, then enclose it in brackets Me.[Type]
Most of the time that will avoid a problem, but not always.
--
Dave Hargis, Microsoft Access MVP


:

I am trying to figure out how to add a button to a form that will print two
different reports based on the record data. The field values are either C or
D (the ones I am concerned with), I have confirmed the field Type is text.
Both reports can be printed using a seperate print function, but I would much
rather take the human error out of the problem.

Private Sub btnLayout_Click()
On Error GoTo Err_btnLayout_Click
Dim stDocName As String
Dim stDocName1 As String
stDocName = "rptLabel03"
stDocName1 = "rptLabel02"

If Me.Type = "C" Or Me.Type = "D" Then
DoCmd.OpenReport stDocName, acNormal, , Me.OpenArgs
Else
DoCmd.OpenReport stDocName1, acNormal, , Me.OpenArgs
End If
DoCmd.Close acForm, "frmLabelSel"

Exit_btnLayout_Click:
Exit Sub

Err_btnLayout_Click:
MsgBox Err.Description
Resume Exit_btnLayout_Click

Every change I have tried to make, I get the second report, not the first.
Help?!
 
G

George Nicholson

Put a Breakpoint on the line that says >Case "C"<, and look to see what
Me.Type in the prior line evaluates as. Null? Something else?

(Just guessing) I'm sure that Type is a Reserved word, so it may be causing
problems. Try changing the control name to txtType, as well as the code
references (Me.txtType), or, as Dave has already suggested, change your code
references to read Me.[Type]. I try to make sure my Controls never share
the same names as my Fields (especially if I'm referring to them in code),
but that may just be me.

HTH,


David Pelizzari said:
Well, it is progress, the logic almost works. When I select a record and
go
to print, no matter what the data is, I get rptlabel02... I checked the
table again, the field Type is set to text, and the characters are all
uppercase.

Klatuu said:
That would work
--
Dave Hargis, Microsoft Access MVP


David Pelizzari said:
Ok, I see where you are going here, I may have been a bit unclear, I
only
want a specific report used if the data is C or D, if else, then print
the
other report. I think I can just replace the error message you put in
with
the other label. More like:

Select Case Me.Type
Case "C"
strDocName = conLabel03
Case "D"
strDocName = conLabel03
Case Else
strDocName = conlabel02



:

The way you have it coded, it will always print out the first report.
Since your values can only be C or D, this statement is always true
If Me.Type = "C" Or Me.Type = "D" Then

Here is how I would do it:

Private Sub btnLayout_Click()
Dim strDocName As String
Const conLabel03 As String = "rptLabel03"
Const conLabel02 As String = "rptLabel02"

On Error GoTo Err_btnLayout_Click

Select Case Me.Type
Case "C"
strDocName = conLabel03
Case "D"
strDocName = conLabel02
Case Else
MsgBox "Invalid Value in Type"
Me.Type.SetFocus
Exit Sub
End Select

DoCmd.OpenReport strDocName, acNormal, , Me.OpenArgs

DoCmd.Close acForm, "frmLabelSel"

Exit_btnLayout_Click:
Exit Sub

Err_btnLayout_Click:
MsgBox Err.Description
Resume Exit_btnLayout_Click
End Sub


One other issue. I see you have a control named Type. You should
not use
Type as a name. It is an Access reserved word. No Access reserved
words
should be used as names. It can confuse Access. If you can't change
the
name, then enclose it in brackets Me.[Type]
Most of the time that will avoid a problem, but not always.
--
Dave Hargis, Microsoft Access MVP


:

I am trying to figure out how to add a button to a form that will
print two
different reports based on the record data. The field values are
either C or
D (the ones I am concerned with), I have confirmed the field Type
is text.
Both reports can be printed using a seperate print function, but I
would much
rather take the human error out of the problem.

Private Sub btnLayout_Click()
On Error GoTo Err_btnLayout_Click
Dim stDocName As String
Dim stDocName1 As String
stDocName = "rptLabel03"
stDocName1 = "rptLabel02"

If Me.Type = "C" Or Me.Type = "D" Then
DoCmd.OpenReport stDocName, acNormal, , Me.OpenArgs
Else
DoCmd.OpenReport stDocName1, acNormal, , Me.OpenArgs
End If
DoCmd.Close acForm, "frmLabelSel"

Exit_btnLayout_Click:
Exit Sub

Err_btnLayout_Click:
MsgBox Err.Description
Resume Exit_btnLayout_Click

Every change I have tried to make, I get the second report, not the
first.
Help?!
 
G

Guest

If I am reading your code right, George, you are wanting to prompt the user
for a type before printing? I am trying to remove the human error factor and
have the print command function select the correct report for them, based on
the record information. So far, the best I can do is get the last case to
work (code examples below), for some reason, the field Type isn't resolving
to either case. I am picking known data of type C and D, but still getting
the other report.

George Nicholson said:
Consider:

Select Case NZ(Me.Type,"")
Case ""
MsgBox "Please select a Type"
Me.Type.SetFocus
Exit Sub
Case "C", "D"
strDocName = conLabel03
Case Else
strDocName = conlabel02
End Select




David Pelizzari said:
Ok, I see where you are going here, I may have been a bit unclear, I only
want a specific report used if the data is C or D, if else, then print the
other report. I think I can just replace the error message you put in
with
the other label. More like:

Select Case Me.Type
Case "C"
strDocName = conLabel03
Case "D"
strDocName = conLabel03
Case Else
strDocName = conlabel02



Klatuu said:
The way you have it coded, it will always print out the first report.
Since your values can only be C or D, this statement is always true
If Me.Type = "C" Or Me.Type = "D" Then

Here is how I would do it:

Private Sub btnLayout_Click()
Dim strDocName As String
Const conLabel03 As String = "rptLabel03"
Const conLabel02 As String = "rptLabel02"

On Error GoTo Err_btnLayout_Click

Select Case Me.Type
Case "C"
strDocName = conLabel03
Case "D"
strDocName = conLabel02
Case Else
MsgBox "Invalid Value in Type"
Me.Type.SetFocus
Exit Sub
End Select

DoCmd.OpenReport strDocName, acNormal, , Me.OpenArgs

DoCmd.Close acForm, "frmLabelSel"

Exit_btnLayout_Click:
Exit Sub

Err_btnLayout_Click:
MsgBox Err.Description
Resume Exit_btnLayout_Click
End Sub


One other issue. I see you have a control named Type. You should not
use
Type as a name. It is an Access reserved word. No Access reserved words
should be used as names. It can confuse Access. If you can't change the
name, then enclose it in brackets Me.[Type]
Most of the time that will avoid a problem, but not always.
--
Dave Hargis, Microsoft Access MVP


:

I am trying to figure out how to add a button to a form that will print
two
different reports based on the record data. The field values are
either C or
D (the ones I am concerned with), I have confirmed the field Type is
text.
Both reports can be printed using a seperate print function, but I
would much
rather take the human error out of the problem.

Private Sub btnLayout_Click()
On Error GoTo Err_btnLayout_Click
Dim stDocName As String
Dim stDocName1 As String
stDocName = "rptLabel03"
stDocName1 = "rptLabel02"

If Me.Type = "C" Or Me.Type = "D" Then
DoCmd.OpenReport stDocName, acNormal, , Me.OpenArgs
Else
DoCmd.OpenReport stDocName1, acNormal, , Me.OpenArgs
End If
DoCmd.Close acForm, "frmLabelSel"

Exit_btnLayout_Click:
Exit Sub

Err_btnLayout_Click:
MsgBox Err.Description
Resume Exit_btnLayout_Click

Every change I have tried to make, I get the second report, not the
first.
Help?!
 
G

Guest

Sorry, George, had a blond moment on my last post, you are putting in kind of
an error check. Not a big programming fan, I just get this stuff tossed at
me...

George Nicholson said:
Consider:

Select Case NZ(Me.Type,"")
Case ""
MsgBox "Please select a Type"
Me.Type.SetFocus
Exit Sub
Case "C", "D"
strDocName = conLabel03
Case Else
strDocName = conlabel02
End Select




David Pelizzari said:
Ok, I see where you are going here, I may have been a bit unclear, I only
want a specific report used if the data is C or D, if else, then print the
other report. I think I can just replace the error message you put in
with
the other label. More like:

Select Case Me.Type
Case "C"
strDocName = conLabel03
Case "D"
strDocName = conLabel03
Case Else
strDocName = conlabel02



Klatuu said:
The way you have it coded, it will always print out the first report.
Since your values can only be C or D, this statement is always true
If Me.Type = "C" Or Me.Type = "D" Then

Here is how I would do it:

Private Sub btnLayout_Click()
Dim strDocName As String
Const conLabel03 As String = "rptLabel03"
Const conLabel02 As String = "rptLabel02"

On Error GoTo Err_btnLayout_Click

Select Case Me.Type
Case "C"
strDocName = conLabel03
Case "D"
strDocName = conLabel02
Case Else
MsgBox "Invalid Value in Type"
Me.Type.SetFocus
Exit Sub
End Select

DoCmd.OpenReport strDocName, acNormal, , Me.OpenArgs

DoCmd.Close acForm, "frmLabelSel"

Exit_btnLayout_Click:
Exit Sub

Err_btnLayout_Click:
MsgBox Err.Description
Resume Exit_btnLayout_Click
End Sub


One other issue. I see you have a control named Type. You should not
use
Type as a name. It is an Access reserved word. No Access reserved words
should be used as names. It can confuse Access. If you can't change the
name, then enclose it in brackets Me.[Type]
Most of the time that will avoid a problem, but not always.
--
Dave Hargis, Microsoft Access MVP


:

I am trying to figure out how to add a button to a form that will print
two
different reports based on the record data. The field values are
either C or
D (the ones I am concerned with), I have confirmed the field Type is
text.
Both reports can be printed using a seperate print function, but I
would much
rather take the human error out of the problem.

Private Sub btnLayout_Click()
On Error GoTo Err_btnLayout_Click
Dim stDocName As String
Dim stDocName1 As String
stDocName = "rptLabel03"
stDocName1 = "rptLabel02"

If Me.Type = "C" Or Me.Type = "D" Then
DoCmd.OpenReport stDocName, acNormal, , Me.OpenArgs
Else
DoCmd.OpenReport stDocName1, acNormal, , Me.OpenArgs
End If
DoCmd.Close acForm, "frmLabelSel"

Exit_btnLayout_Click:
Exit Sub

Err_btnLayout_Click:
MsgBox Err.Description
Resume Exit_btnLayout_Click

Every change I have tried to make, I get the second report, not the
first.
Help?!
 
G

Guest

Thanks, George, your code proves that for some reason, even though the field
"Type" has data in it as C, D, G, etc... it is not coming over to the print
function. Which makes me more confused, because it is getting passed to the
report and printing.

I knew there was a reason I stopped taking programming classes, I hate code
logic! :)

George Nicholson said:
Consider:

Select Case NZ(Me.Type,"")
Case ""
MsgBox "Please select a Type"
Me.Type.SetFocus
Exit Sub
Case "C", "D"
strDocName = conLabel03
Case Else
strDocName = conlabel02
End Select




David Pelizzari said:
Ok, I see where you are going here, I may have been a bit unclear, I only
want a specific report used if the data is C or D, if else, then print the
other report. I think I can just replace the error message you put in
with
the other label. More like:

Select Case Me.Type
Case "C"
strDocName = conLabel03
Case "D"
strDocName = conLabel03
Case Else
strDocName = conlabel02



Klatuu said:
The way you have it coded, it will always print out the first report.
Since your values can only be C or D, this statement is always true
If Me.Type = "C" Or Me.Type = "D" Then

Here is how I would do it:

Private Sub btnLayout_Click()
Dim strDocName As String
Const conLabel03 As String = "rptLabel03"
Const conLabel02 As String = "rptLabel02"

On Error GoTo Err_btnLayout_Click

Select Case Me.Type
Case "C"
strDocName = conLabel03
Case "D"
strDocName = conLabel02
Case Else
MsgBox "Invalid Value in Type"
Me.Type.SetFocus
Exit Sub
End Select

DoCmd.OpenReport strDocName, acNormal, , Me.OpenArgs

DoCmd.Close acForm, "frmLabelSel"

Exit_btnLayout_Click:
Exit Sub

Err_btnLayout_Click:
MsgBox Err.Description
Resume Exit_btnLayout_Click
End Sub


One other issue. I see you have a control named Type. You should not
use
Type as a name. It is an Access reserved word. No Access reserved words
should be used as names. It can confuse Access. If you can't change the
name, then enclose it in brackets Me.[Type]
Most of the time that will avoid a problem, but not always.
--
Dave Hargis, Microsoft Access MVP


:

I am trying to figure out how to add a button to a form that will print
two
different reports based on the record data. The field values are
either C or
D (the ones I am concerned with), I have confirmed the field Type is
text.
Both reports can be printed using a seperate print function, but I
would much
rather take the human error out of the problem.

Private Sub btnLayout_Click()
On Error GoTo Err_btnLayout_Click
Dim stDocName As String
Dim stDocName1 As String
stDocName = "rptLabel03"
stDocName1 = "rptLabel02"

If Me.Type = "C" Or Me.Type = "D" Then
DoCmd.OpenReport stDocName, acNormal, , Me.OpenArgs
Else
DoCmd.OpenReport stDocName1, acNormal, , Me.OpenArgs
End If
DoCmd.Close acForm, "frmLabelSel"

Exit_btnLayout_Click:
Exit Sub

Err_btnLayout_Click:
MsgBox Err.Description
Resume Exit_btnLayout_Click

Every change I have tried to make, I get the second report, not the
first.
Help?!
 
G

George Nicholson

even though the field "Type" has data in it ...

Me.Type in your code refers to a Control, not a field. What does the
*Control* contain when the code runs?

[Yes, if your control is bound to a field called Type, the values would
likely be the same - although timing might matter. In any case, we're
trying to track down why it isn't working so I'm getting picky about
terminology. :) ]

If you haven't already, please heed the earlier suggestions from Dave &
myself about renaming your control or referring to the control with brackets
(i.e., Me.[Type]). That may not be the problem, but it would sure be nice to
eliminate it as a possibility.
Once you do that, please re-post your current code if it still isn't
working.

HTH,

David Pelizzari said:
Thanks, George, your code proves that for some reason, even though the
field
"Type" has data in it as C, D, G, etc... it is not coming over to the
print
function. Which makes me more confused, because it is getting passed to
the
report and printing.

I knew there was a reason I stopped taking programming classes, I hate
code
logic! :)

George Nicholson said:
Consider:

Select Case NZ(Me.Type,"")
Case ""
MsgBox "Please select a Type"
Me.Type.SetFocus
Exit Sub
Case "C", "D"
strDocName = conLabel03
Case Else
strDocName = conlabel02
End Select




David Pelizzari said:
Ok, I see where you are going here, I may have been a bit unclear, I
only
want a specific report used if the data is C or D, if else, then print
the
other report. I think I can just replace the error message you put in
with
the other label. More like:

Select Case Me.Type
Case "C"
strDocName = conLabel03
Case "D"
strDocName = conLabel03
Case Else
strDocName = conlabel02



:

The way you have it coded, it will always print out the first report.
Since your values can only be C or D, this statement is always true
If Me.Type = "C" Or Me.Type = "D" Then

Here is how I would do it:

Private Sub btnLayout_Click()
Dim strDocName As String
Const conLabel03 As String = "rptLabel03"
Const conLabel02 As String = "rptLabel02"

On Error GoTo Err_btnLayout_Click

Select Case Me.Type
Case "C"
strDocName = conLabel03
Case "D"
strDocName = conLabel02
Case Else
MsgBox "Invalid Value in Type"
Me.Type.SetFocus
Exit Sub
End Select

DoCmd.OpenReport strDocName, acNormal, , Me.OpenArgs

DoCmd.Close acForm, "frmLabelSel"

Exit_btnLayout_Click:
Exit Sub

Err_btnLayout_Click:
MsgBox Err.Description
Resume Exit_btnLayout_Click
End Sub


One other issue. I see you have a control named Type. You should not
use
Type as a name. It is an Access reserved word. No Access reserved
words
should be used as names. It can confuse Access. If you can't change
the
name, then enclose it in brackets Me.[Type]
Most of the time that will avoid a problem, but not always.
--
Dave Hargis, Microsoft Access MVP


:

I am trying to figure out how to add a button to a form that will
print
two
different reports based on the record data. The field values are
either C or
D (the ones I am concerned with), I have confirmed the field Type is
text.
Both reports can be printed using a seperate print function, but I
would much
rather take the human error out of the problem.

Private Sub btnLayout_Click()
On Error GoTo Err_btnLayout_Click
Dim stDocName As String
Dim stDocName1 As String
stDocName = "rptLabel03"
stDocName1 = "rptLabel02"

If Me.Type = "C" Or Me.Type = "D" Then
DoCmd.OpenReport stDocName, acNormal, , Me.OpenArgs
Else
DoCmd.OpenReport stDocName1, acNormal, , Me.OpenArgs
End If
DoCmd.Close acForm, "frmLabelSel"

Exit_btnLayout_Click:
Exit Sub

Err_btnLayout_Click:
MsgBox Err.Description
Resume Exit_btnLayout_Click

Every change I have tried to make, I get the second report, not the
first.
Help?!
 

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

Similar Threads


Top