pre-processing entered data prior to updating the target field

peskywinnets

Registered User.
Local time
Today, 01:47
Joined
Feb 4, 2014
Messages
578
Tearing my hair out here (I've not worked with forms much, must be missing the point here!)

I'll keep it simple.....let's say I have a table with a field in it called "Barcode"

So I have a form setup with the field Barcode showing (ready to accept input)

What I want to do is take the data entered (it will actually be a scanned barcode), but only use part of the data ...and have extracted data that go to the target field called Barcode, so something like this...

MyBarcode = Mid(Trim(Barcode), 11, 11)
Barcode = MyBarcode

but I can't seem to get access to update the Barcode with MyBarcode.

I'm using the Before Update option & I get this error message....

Screenshot.jpg


....any tips please?
 
Try the after update event if you're changing the data.
 
Hi. Try moving your code to the AfterUpdate event...

Edit: Oops, too slow... Sorry for the duplicate information...
 
Thanks guys...that seems to have done it (I'm pretty sure I tried that earlier, but having spent quite some time on this my head is a bit fried so perhaps there was another issue at that point!)
 
No problem. We've all had the fried head at some point. ;)
 
Validation code belongs in the BeforeUpdate event (of the control or the form) but if you have to modify the value, you have to use the control's AfterUpdate event. Technically, this isn't validation code. You always want to modify the scanned data. Normally, I use the Form's BeforeUpdate event which would let this code work. That means that the scan value wouldn't be trimmed until just before the record is saved which might be undesirable for this situation.

Another alternative (which might actually help for testing) is to put the barcode into an unbound control. Then in the BeforeUpdate event of the unbound control, you can use your code to populate the bound control. The Bound control in this case would have its locked property set to Yes to ensure that the scan only goes into the unbound control.
 

Users who are viewing this thread

Back
Top Bottom