ben2203
Dec 7 2009, 10:07 AM
Hi All,
I want to build an if statement for 3 separate conditions
right now, I have this:
Private Sub txtPaymentSelector_AfterUpdate()
If txtPaymentSelector = 3 Then
Me.txtCreditDate.Enabled = True
Me.txtCreditDate.Value = Date + 30
Me.txtPaymentDetail = "The Bill is Payable on" & Date + 30
Me.txtCashTendered.Enabled = False
Else
Me.txtCashTendered.Enabled = True
Me.txtCreditDate.Enabled = False
Me.txtCreditDate.Value = Null
Me.txtPaymentDetail.Value = Null
End If
Me.Refresh
End Sub
But I need to put in a third condition so if the payment selector's value is 1 then it will enable some other controls on my form.
What is the correct syntax to achieve this? Something to do with Else if right? but actually tried that and it doesn't work.
Thanks in advance
Edited by: ben2203 on Mon Dec 7 10:08:35 EST 2009.
Peter46
Dec 7 2009, 10:10 AM
If txtPaymentSelector = 3 Then
......
Elseif txtPaymentSelector = 1 Then
.....
else
......
End If
You can also consider a Select Case command but for this example there is nothing much to choose between them.
ben2203
Dec 7 2009, 10:16 AM
How strange,
tried elseif first and it came up with some syntax, second time around after clarification it works??
anyway, thanks very much
Alan_G
Dec 7 2009, 10:27 AM
Hi
Another option is the Select Case construct
CODE
Private Sub txtPaymentSelector_AfterUpdate()
Select Case Me.txtPaymentSelector
Case 1
'code if value = 1
Case 2
Me.txtCashTendered.Enabled = True
Me.txtCreditDate.Enabled = False
Me.txtCreditDate.Value = Null
Me.txtPaymentDetail.Value = Null
Case 3
Me.txtCreditDate.Enabled = True
Me.txtCreditDate.Value = Date + 30
Me.txtPaymentDetail = "The Bill is Payable on" & Date + 30
Me.txtCashTendered.Enabled = False
Case Else
'code if none of the values are matched
End Select
ben2203
Dec 7 2009, 10:58 AM
Argh, yes, I remember that also now, thanks guys
I opted with the first one but I'll remember that for future projects.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.