Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code not working in before_insert event 1

Status
Not open for further replies.

ImStuk

Technical User
Feb 20, 2003
62
US
I use the following code to automatically number entities in a subForm. I keep getting the error "you can't assign a value to this object". It works great in an old Access '97 database I made 2 years ago and converted to Access 2000, but I am making another database with the same form and I get that error. Can somebody see what I am missing. I really appreciate any help.

Option Compare Database

Private Sub Form_BeforeInsert(Cancel As Integer)
On Error GoTo Err_Form_BeforeInsert
Me.txtEntityID = NewEntityID 'This is a Function I use to create the unique entityID'
Me.txtEntityNumber = Nz(DMax("[EntityNumber]", "tblEntities", "[OrderNumber] =" & [txtOrderNumber]), 0) + 1
Exit_Form_BeforeInsert:
Exit Sub
Err_Form_BeforeInsert:
MsgBox Err.Description
Resume Exit_Form_BeforeInsert
End Sub
 
Make sure you don't have an autonumber field in the table of the name txtEntityID.
If the name of the control and Control Source are the same, this can create a conflict in some cases.

A way around this is to have a control of a name other than the control source field. Assign value to the control name instead of field name
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top