need help with timer on access form

TechRetard

New member
Local time
Today, 09:49
Joined
Aug 8, 2009
Messages
2
Ok, so I have a form that has a few fields on it, including ID and Timezone ("AZ", "Eastern", etc). I have a text box and search button which is used to quickly bring up all the fields for the ID in the text box.

I want to add a digital clock ("timer") to the form, but i want it to change to the correct time based on the timezone on the form. Say for example I live in AZ, so time Now() will be set, but when i enter a 2 (ID #2) in the text box and click search, it displays results for my #2 which has an Eastern Time zone (+3 hours) I would like the timer to add 3 hours....

I can add a timer to the form using: (having a textbox on the form named "Timer1")

Code:
Private Sub Form_Load()
Me.TimerInterval = 1000
End Sub
 
Private Sub Form_Timer()
    [Timer1] = Now()
End Sub

Also, I can add an If statement to the form_timer (if timezone.text = "eastern" then etc...but i have to set focus to the time zone text box first...but then it's always setting focus to that box and I can't type anything in my search box :-(

Does this make sense...any ideas??
 
Hello and Welcome!

You shouldn't be so hard on yourself - we're all deficient to some degree with our tech abilities ;)

So there are 3 things for you to consider:
(1) The "DateAdd" function
(2) The ".Value" property
(3) "Select Case" control structure

With DateAdd, your [Timer1] value becomes (assuming it's set the "Eastern"):
Code:
[Timer1] = DateAdd("h", 3, Now())

With the .Value property, you don't need to set focus to the control to read the contents, as opposed to the .Text property.

Finally, Select Case is good to make things clear in code when you might have to test for multiple possibilities:
Code:
Dim intAdjustedHours As Integer

Select Case Me!timezone.Value
 Case "Eastern"
    intAdjustedHours = 3
 Case "Central"
    intAdjustedHours = 2
 Case "Pacific"
    intAdjustedHours = -1
 Case Else
    'if this option means "AZ", then do nothing
    'or add code to handle as appropriate
End Select
So, with the above Select Case code, your [Timer1] assignment changes to:
Code:
[Timer1] = DateAdd("h", intAdjustedHours, Now())

HTH,
John
 
Ahhh .Value ... i came accross everything online except that (not used to vba)

I spent about 3 hours on this, and coded the same thing in C#.net in 10 min lol...but it is working now, thank you so much :-)
 
Glad you got things working!

So with your C#.net background, I'm inclined to believe your moniker is very tongue-in-cheek ;)

Cheers,
John
 

Users who are viewing this thread

Back
Top Bottom