Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access If Statement 2

Status
Not open for further replies.

MichaelF81

Programmer
Sep 20, 2005
178
US
Can someone please just post a simple if statement example in access. 2 text boxes and a label. I want the labels value to change based on what is in text box 1, or that is empty, what is in textbox 2.

Thanks




"Adults are just obsolete children and the hell with them." - Dr. Seuss
 
Dim strLabel

If IsNull([TextBox1]) Then

strLabel = Me.TextBox2

Me.MyLabel.Caption = strLabel

Else

strLabel = Me.TextBox1

Me.MyLabel.Caption = strLabel

End If
 
Thanks




"Adults are just obsolete children and the hell with them." - Dr. Seuss
 
Just for fun, a one line version:
Me!MyLabel.Caption = Nz(Me!TextBox1, Me!TextBox2)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Nice one PHV


I always forget about using Nz

:-(
 
I never really use it, I always forget too

Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

If Not IsNull(Me.Text71a) Then
Dim v1, v2 As Integer
v1 = Me.Text71
v2 = Me.Text71a
  If v1 < v2 Then
   Me.lblCalc.Caption = Round(v1, 0)
  Else
   Me.lblCalc.Caption = Round(v2, 0)
  End If
Else
Me.lblCalc.Caption = ""
End If

If Not IsNull(Me.Text77a) Then
Dim v3, v4 As Integer
v3 = Me.Text77
v4 = Me.Text77a
  If v3 < v4 Then
   Me.lblCalc1.Caption = Round(v3, 0)
  Else
   Me.lblCalc1.Caption = Round(v4, 0)
  End If
Else
Me.lblCalc1.Caption = ""
End If

End Sub




"Adults are just obsolete children and the hell with them." - Dr. Seuss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top