UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> multiple if statements    
 
   
ben2203
post Dec 7 2009, 10:07 AM
Post #1

UtterAccess Guru
Posts: 868
From: BKK



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.
Go to the top of the page
 
+
Peter46
post Dec 7 2009, 10:10 AM
Post #2

UtterAccess VIP
Posts: 7,394
From: Oadby Leics, UK



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.
Go to the top of the page
 
+
ben2203
post Dec 7 2009, 10:16 AM
Post #3

UtterAccess Guru
Posts: 868
From: BKK



How strange,

tried elseif first and it came up with some syntax, second time around after clarification it works??

anyway, thanks very much
Go to the top of the page
 
+
Alan_G
post Dec 7 2009, 10:27 AM
Post #4

Utterly Yorkshire and Forum/Wiki Editor
Posts: 15,881
From: Devon UK



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
Go to the top of the page
 
+
ben2203
post Dec 7 2009, 10:58 AM
Post #5

UtterAccess Guru
Posts: 868
From: BKK



Argh, yes, I remember that also now, thanks guys

I opted with the first one but I'll remember that for future projects.
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 19th May 2013 - 03:15 AM