Simple VBA If/Then Statement Not Working

Reese

Registered User.
Local time
Today, 14:03
Joined
Jan 13, 2013
Messages
387
[Solved] Simple VBA If/Then Statement Not Working

I have 2 combo lists that are formatted to Medium Time with the following values for the row source:

PartyTimeCombo: "10:30 AM";"12:30 PM"
EndTimeTxt: "1:30 PM";"3:30 PM"

I have the following event procedure as an AfterUpdate function for PartyTimeCombo:

Code:
Private Sub PartyTimeCombo_AfterUpdate()

If Me.PartyTimeCombo = "10:30 AM" Then
    Me.EndTimeTxt = "12:30 PM"
ElseIf Me.PartyTimeCombo = "1:30 PM" Then
    Me.EndTimeTxt = "3:30 PM"
End If
DoCmd.RunCommand acCmdRefresh

End Sub
For some reason it doesn't work. It's been like that since I made it--over a year ago. I never bothered looking too much into it because it's not that big of a deal. But now I'm going through and streamlining some stuff in the code so figured I'd try to fix it.

Anyone have any ideas? And no, Compact/Repair doesn't do anything and nothing comes up with Compiling the code under the Debug option menu.
 
Last edited:
Is PartyTimeCombo bound to a field? If so, what field type is it?

If it's a date/time then the data that's stored contains a date that you're just not displaying in the combo box, but you'd need to include it in your IF statement to make a valid comparison.

To see what value PartyTimeCombo has, just add a line outside of the if/then:

Code:
Debug.print me.partytimecombo

Then update the combo and see what value pops up in the Immediate window in your VB editor. That's the value you need to use in your IF statement.
 
Thanks for the suggestions, guys.

Nickthompson, your solution worked. Both the combos and the bound fields were set to Medium Time format, which apparently requires seconds to be included (i.e. 10:30:00 AM). I never realized that, made the changes and it works fine.

Thanks!
 

Users who are viewing this thread

Back
Top Bottom