Creating a time out function

rede96

Registered User.
Local time
Today, 03:25
Joined
Apr 2, 2004
Messages
134
Hi all :)

I have a DB set up to receive data from a scanner through a virtual COM port. I manipulate the received scan data in VBA before writing the result to various tables.

For certain scans, I'd like the user to confirm the scanned barcodes by scanning it again within the a certain time limit (Say 1 minute)

So in my code, once that specific barcode has been detected, I want to code to wait for 1 minute to see if the scan comes through again.

The application.wait isn't really suitable as this stops the next scan being registered until the wait is done.

Anyone know of any simple ways around this please?
 
Hello Rede96,

If I understand your requirement correctly, you are wanting Access to process two or more transactions at the same time. If I have this right, then I am certain Access (the Jet engine) cannot do this. There has been a few discussions on this forum regarding asynchronous processing and folks a lot smarter than me have spoke to this issue.

I could be wrong of course...
 
Code:
Public Function Pause(PauseSeconds As Long)

    Dim StartTime As Long
         StartTime = Timer
    
         Do While Timer < StartTime + PauseSeconds
                 DoEvents   'keep running other processes
         Loop
End Function
DoEvents allows Access to handle other events that might be raised while you code runs (like your background process).
 
Last edited:
Hello Rede96,

If I understand your requirement correctly, you are wanting Access to process two or more transactions at the same time. If I have this right, then I am certain Access (the Jet engine) cannot do this. There has been a few discussions on this forum regarding asynchronous processing and folks a lot smarter than me have spoke to this issue.

I could be wrong of course...

Hi and thanks for the reply. Yes I think you may be right from what I've read so far. I think I have a way around it by exiting the code, opening up a hidden form and setting a timer event. But it's messy and I have to hold all the variables and re-hash my code so I am jump back in at the point I left.

What I don't get is that I can have 2 forms running timer events at the same time, but I can't do that in vba?
 
Young Squire, you are in the deep part of the pool were very few (I am not included) are allowed to swim without lifeguard supervision. Not to worry, they will see this soon enough and throw you a life jacket...

Ashlee's code looks right, but I do not think it will achieve what you want it to...but then, I am still in the kiddie pool learning to dog-paddle!
 
Presumably you do have a form open somewhere at the same time, right? You could set that form's OnTimer event with VBA, and have it call a VBA function when the time is up.

My other suggestion should work too - as long as it has that DoEvents function - and depending on how badly your scanner hardware ties up the system.
 
Looking at ashleedawg's post, I looked at the link she provided. I am a little familiar with DoEvents but had not seen this particular link before. Within this link is a link to Multi threading. Looks like I have a rabbit-hole to go down...
 
Presumably you do have a form open somewhere at the same time, right? You could set that form's OnTimer event with VBA, and have it call a VBA function when the time is up.

Thanks for your post and link. I do have one form open but I already use it's on timer event for something else. I suppose I could make it shorter and have a duel purpose I suppose. But opening another form in the background which is hidden seems better to me.

I've not come across doevents before so will have to have a read up. But thanks anyway.
 
Looking at ashleedawg's post, I looked at the link she provided. I am a little familiar with DoEvents but had not seen this particular link before. Within this link is a link to Multi threading. Looks like I have a rabbit-hole to go down...

Lol, sounds an interesting rabbit hole! I might join you when I get some time. Thanks for the link.
 
I am sure you can do this with a class.

you need a barcode class to store details of each barcode scanned
delete the class instance for handled barcodes

so when you scan a barcode you first check the pending events to see if there is a match.

if not handle it as a new one.

so now, all you need is a timer event to iterate the pending requests, and ask whether overdue ones should be dismissed, or wait for a further period.

you could even do this without a class - just put all the pending barcodes in a table, and manipulate the table with similar functionality.


Hope this gives you some ideas
 
This scenario is just like a user having to re-enter a password or email address to confirm.

Set up a second text box to enter the confirmed scan, have a timer event in the entry form as suggested by Ashlee, and in the after update or maybe onChange, event of the confirming text box, turn off the timer and do whatever with the data entered.

BTW, the scanner imposes no more load on the system than the keyboard does because it only replaces keyboard action and enters the string in one action rather than several key presses.
 
BTW, the scanner imposes no more load on the system than the keyboard does because it only replaces keyboard action and enters the string in one action rather than several key presses.

Unfortunately the scanner is set up using a virtual com and not keyboard wedge. So it doesn't emulate a keyboard. There is an ondata event triggered by an activex control I use to listen to the virtual com port. Once the event is triggered it starts some code to check and manipulate the data. It's during this process where the code will highlight that a confirmation scan needs to be done before continuing to process the data form the scan and write the output to various tables.

So the only way I can think of is to hold all the variables, exit the code and open a hidden form with a timer event. I'd then need to redirect the scan result to this form and if it is received within the time limit I can step back into my code. Although I'd have to create a new sub for 'part 2' if you will.

That's the only way I can think of. Unless anyone has any other ideas. :)
 
Unfortunately the scanner is set up using a virtual com and not keyboard wedge
That was not my point about using system resources but rather using the scanner itself is the same load as using the keyboard to enter the scanned data.

That's the only way I can think of. Unless anyone has any other ideas.
What's wrong with the method I offered in para 2 of my previous post, only using your activeX event to trigger the comparison with the re-scanned data? You don't need a hidden form for the timer, use the open form.

Assuming you have 2 text boxes, txtScanData, txtRescanData
Code:
sub CalledFromactiveX_event()
     if len(me.txtScanData &"")>0 then
          if len(me.txtRescanData &"") =0 then
             'initial scan
              me.timer=10000  '10 second delay before checking rescan has occured
         else
              'rescanned
               me.timer =0
              <do whatever now scan has been confirmed>
              me.txtscan = null
               me.txtRescan= null
         endif
     endif
end sub
 
What's wrong with the method I offered in para 2 of my previous post, only using your activeX event to trigger the comparison with the re-scanned data? You don't need a hidden form for the timer, use the open form.

Assuming you have 2 text boxes, txtScanData, txtRescanData
Code:
sub CalledFromactiveX_event()
     if len(me.txtScanData &"")>0 then
          if len(me.txtRescanData &"") =0 then
             'initial scan
              me.timer=10000  '10 second delay before checking rescan has occured
         else
              'rescanned
               me.timer =0
              <do whatever now scan has been confirmed>
              me.txtscan = null
               me.txtRescan= null
         endif
     endif
end sub

Thanak for the help. But the open form already runs a timer even to update charts as well as a few other controls. Hence why I'd open another form. It's just cleaner that way but basically I'm going the in a similar way to your suggestion.
 

Users who are viewing this thread

Back
Top Bottom