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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert a generated unique ID based on an autonumber. 1

Status
Not open for further replies.

cdgeer

IS-IT--Management
Apr 8, 2008
133
US
I have a form for a table with 2 unique ID fields. 1 is an autonumber used for audit trail purposes(Primary key) and the other called "EEID" is just a number (Long Int). When entering a record in the form, sometimes the EEID # is available but sometimes is not. If not, I would like to have a command button that would take the autonumber generated by the new record, add 999,999 to make sure it will always be higher than any other existing EEID#s(which are all lower than 999999)and insert it into the EEID field. Does anyone no how to write the VB Code for this cmd? I'm not that good at VB yet.
Thanks in advance for any help!
Fields:
"audID" is Autonumber Type
"EEID" is Number Type
 
Something like the following should do:

I've assumed that you are using the txt prefix for control names on your form rather than write to the database fieldname directly.

Code:
Private Sub cmdGenerateEEID_Click()

  If IsNull (Me!txtEEID)  Then
    Me!txtEEID = Me!audID + 999999
  End If

End Sub

John
 
Thanks so much jrbarnett!!

I was able to use this but used a LostFocus event instead.

Works perfect! thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top