pre-processing entered data prior to updating the target field (1 Viewer)

peskywinnets

Registered User.
Local time
Today, 05:41
Joined
Feb 4, 2014
Messages
576
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?
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 21:41
Joined
Aug 30, 2003
Messages
36,125
Try the after update event if you're changing the data.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 21:41
Joined
Oct 29, 2018
Messages
21,467
Hi. Try moving your code to the AfterUpdate event...

Edit: Oops, too slow... Sorry for the duplicate information...
 

peskywinnets

Registered User.
Local time
Today, 05:41
Joined
Feb 4, 2014
Messages
576
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!)
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 21:41
Joined
Aug 30, 2003
Messages
36,125
No problem. We've all had the fried head at some point. ;)
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 00:41
Joined
Feb 19, 2002
Messages
43,263
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

Top Bottom