IF, THEN, ELSE PRINT BUTTON

  • Thread starter Thread starter Gilberto Lawas via AccessMonster.com
  • Start date Start date
G

Gilberto Lawas via AccessMonster.com

Hello,
I am trying to make an [EventProcedure] on a print button with an IF,
THEN statement. I am a very new user and could use a little VB help.
The table I'm using has 3 fields: [RefOne], [RefTwo], [RefThree] and 3
reports: "Ref Letter", "Ref Letter1", "Ref Letter2"

Basically I want the print button to say:

If [RefOne] (is not blank), Then print "Ref Letter"
If [RefTwo] (is not blank), Then print "Ref Letter1"
If [RefThree] (is not blank0, Then print "Ref Letter2"

But I don't know how to write it. So far this is what I have on the
button.

Private Sub Ref_Letter_Click()
On Error GoTo Err_Ref_Letter_Click

Dim stDocName As String

stDocName = "Ref Letter"
DoCmd.OpenReport stDocName, acNormal

Exit_Ref_Letter_Click:
Exit Sub

Err_Ref_Letter_Click:
MsgBox Err.Description
Resume Exit_Ref_Letter_Click

End Sub

r/s
clueless
 
Gilberto Lawas via AccessMonster.com said:
Hello,
I am trying to make an [EventProcedure] on a print button with an IF,
THEN statement. I am a very new user and could use a little VB help.
The table I'm using has 3 fields: [RefOne], [RefTwo], [RefThree] and 3
reports: "Ref Letter", "Ref Letter1", "Ref Letter2"

Basically I want the print button to say:

If [RefOne] (is not blank), Then print "Ref Letter"
If [RefTwo] (is not blank), Then print "Ref Letter1"
If [RefThree] (is not blank0, Then print "Ref Letter2"

But I don't know how to write it. So far this is what I have on the
button.

Private Sub Ref_Letter_Click()
On Error GoTo Err_Ref_Letter_Click

Dim stDocName As String

stDocName = "Ref Letter"
DoCmd.OpenReport stDocName, acNormal

Exit_Ref_Letter_Click:
Exit Sub

Err_Ref_Letter_Click:
MsgBox Err.Description
Resume Exit_Ref_Letter_Click

End Sub

r/s
clueless

This will print just one of the letters:

If Nz([RefOne]) <> "" Then
stDocName = "Ref Letter"
ElseIf Nz([RefTwo]) <> "" Then
stDocName = "Ref Letter1"
ElseIf Nz([RefThree]) <> "" Then
stDocName = "Ref Letter2"

DoCmd.OpenReport stDocName, acNormal

This could print more than one:

If Nz([RefOne]) <> "" Then _
DoCmd.OpenReport "Ref Letter", acNormal
If Nz([RefTwo]) <> "" Then _
DoCmd.OpenReport "Ref Letter1", acNormal
If Nz([RefThree]) <> "" Then _
DoCmd.OpenReport "Ref Letter2", acNormal
 
Thank You Very Much.

I'll put it in now.

So <>"" means "not blank"
 
Gilberto Lawas via AccessMonster.com said:
Thank You Very Much.

I'll put it in now.

So <>"" means "not blank"

Yes. "" is a zero-length string, and <> means "not equal to", so <>"" means
"not equal to a zero-length string".

However, before you get far with Access, you will need to understand the
difference between Null and a zero-length string. A field containing a
zero-length string has a value: it's a string which happens to be
zero-length. However, the field could instead be Null, which means it's
value is undefined, which is not the same thing at all. A field can only
contain a zero-length string if you put a zero-length string into it,
whereas if you have put nothing into a field, it will be Null.

This is the point of using the Nz() function, which returns a zero-length
string from a Null field i.e. whilst [RefOne] could be Null or could be a
zero-length string, Nz([RefOne]) will always give you a zero-length string,
even if [RefOne] is Null (unless, of course, [RefOne] is not Null, in which
case you will get whatever it's value is).
 
Back
Top