Erika said:
Ok - it works great but I have no more question - is there
something we can add to the code so if it doesn't
recognize the employee number being entered it will start
a new record? Currently if I enter a new employee number
the information that was there (first name, Last name,
etc.) stays the same and doesn't update. I am wondering
if there is some why to say if it doesn't recognize the
number entered - make this a new record?
Does that make sense?
So, then, if you're on an existing record, entering a recognized
employee number should take you to that record, and entering an
unrecognized one should take you to a new record with that employee
number pre-entered? How about this:
'----- start of example code -----
Private Sub EmployeeNumber_AfterUpdate()
Dim varNewEmpNo As Variant
If Not Me.NewRecord Then
varNewEmpNo = Me.EmployeeNumber
Me.Undo
With Me.RecordsetClone
.FindFirst "EmployeeNumber = " & varNewEmpNo
If .NoMatch Then
RunCommand acCmdRecordsGoToNew
Me.EmployeeNumber = varNewEmpNo
Else
Me.Bookmark = .Bookmark
End If
End With
End If
End Sub
'----- end of example code -----
That's untested "air code", and it will prove awkward if someone goes to
a record, modifies fields other than the employee number, then modifies
the employee number to go to another record. In that case, the user's
changes to the first record won't be saved. I don't see a good way
around that, off the top of my head, unless you force the current record
to be saved (if it's Dirty) every time control enteres the
EmployeeNumber control. Further, what will you do if you need to change
an employee's EmployeeNumber? You will not be able to do it with this
form.
I have to say that I don't like overloading a control to make it serve
both for data entry and navigation. It's too susceptible to problems
like the ones I've described.