Avatar of Jeremy Campbell
Jeremy CampbellFlag for United States of America

asked on 

Trying to Troubleshoot Form_Timer Code for if statement using DateDiff in Access Form

I have a code on a continuous form that I'm trying to get the Form_Timer function to GoTo a new record if the current record's TimeIn is 60 seconds less than the CurrentTime. So once the record has been sitting there for 60 seconds, based on the TimeIn then it moves to a new record and sets focus to OperID.

Here is my current VBA that is not working.

Private Sub Form_Timer()

Me.Refresh

If DateDiff("s", Me.TimeIn, Time()) > 60 Then

Me.Refresh

DoCmd.GoToRecord , , acNewRec
Me.OperID.SetFocus
Else

End

End If

End Sub
Microsoft Access

Avatar of undefined
Last Comment
Jeremy Campbell
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

where are the rest of the codes?

did you set the form's timer in the afterupdate event of "TimeIn" ?
Avatar of Jeremy Campbell

ASKER

My apologies, yes I set the time to 10 seconds at the Form_Load event.. Probably should have mentioned that. Here is the code for that.


Private Sub Form_Load()

Me.Form.TimerInterval = 10000


End Sub


I want it to refresh every 10 seconds no matter what, but if it sees that the current record TimeIn meets the criteria of the if statement then proceed with going to a new record and setting focus to OperID of that new record.

Thanks for looking into this for me!
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Do you need to set a new "Time In" when you move to a new record:

Private Sub Form_Timer()

Me.Refresh

If DateDiff("s", Me.TimeIn, Time()) > 60 Then

Me.Refresh

DoCmd.GoToRecord , , acNewRec
Me.TimeIn = Time()  '<--- Add this
Me.OperID.SetFocus
Else

End

End If

End Sub 

Open in new window

Avatar of mbizup
mbizup
Flag of Kazakhstan image

I  think your DateDif might be returning a negative value too.

Try this instead:

If Abs(DateDiff("s", Me.TimeIn, Time())) > 60 Then

Open in new window


Or this:


If DateDiff("s",  Time(), Me.TimeIn ) > 60 Then 

Open in new window

SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
ASKER CERTIFIED SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Jeremy Campbell

ASKER

Didn't modify the code as far as I can tell and it started working. Was led to this using Capricorns MsgBox
Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo