Ken;
Thanks for your help. Here is the module's code
Jim
----------------------------------------Cut line---------------------------
Option Compare Database
Option Explicit
Dim WithEvents frmEmp As Form_frmEmpMaint 'This event is not firing
during the problem time
Public Event NewEmp(recPos As Form)
Public Event CurrentRec(recPos As Form)
Private Sub cboDeptID_Click()
txtDeptID.Value = cboDeptID.Column(0)
txtDeptName.Value = cboDeptID.Column(1)
Facility = 472
txtJobCode.SetFocus ' This is failing I tried pointing to
the next field in the tab order.
End Sub
Private Sub cboDeptID_GotFocus()
cboDeptID.Dropdown
End Sub
Private Sub cboDeptID_LostFocus()
txtDeptID.Visible = True
txtDeptID.SetFocus
cboDeptID.Visible = False
End Sub
Private Sub cboJobCode_Click()
txtJobCode = cboJobCode.Column(0)
txtJobDscr = cboJobCode.Column(1)
'Tried the
routine here initially, but it failed
'So I
moved it to the LostFocus event handler below
End Sub
Private Sub cboJobCode_LostFocus()
txtJobCode.Visible = True
txtJobCode.SetFocus
cboJobCode.Visible = False ' This is failing also
****************
End Sub
Private Sub cmdFirst_Click()
On Error GoTo Err_cmdFirst_Click
DoCmd.GoToRecord , , acFirst
Exit_cmdFirst_Click:
Exit Sub
Err_cmdFirst_Click:
MsgBox Err.Description
Resume Exit_cmdFirst_Click
End Sub
Private Sub cmdPrevious_Click()
On Error GoTo Err_cmdPrevious_Click
DoCmd.GoToRecord , , acPrevious
Exit_cmdPrevious_Click:
Exit Sub
Err_cmdPrevious_Click:
MsgBox Err.Description
Resume Exit_cmdPrevious_Click
End Sub
Private Sub cmdNext_Click()
On Error GoTo Err_cmdNext_Click
DoCmd.GoToRecord , , acNext
Exit_cmdNext_Click:
Exit Sub
Err_cmdNext_Click:
MsgBox Err.Description
Resume Exit_cmdNext_Click
End Sub
Private Sub cmdLast_Click()
On Error GoTo Err_cmdLast_Click
DoCmd.GoToRecord , , acLast
Exit_cmdLast_Click:
Exit Sub
Err_cmdLast_Click:
MsgBox Err.Description
Resume Exit_cmdLast_Click
End Sub
Private Sub CmdNew_Click()
On Error GoTo Err_CmdNew_Click
DoCmd.GoToRecord , , acNewRec
Exit_CmdNew_Click:
Exit Sub
Err_CmdNew_Click:
MsgBox Err.Description
Resume Exit_CmdNew_Click
End Sub
Private Sub dteEffectiveDate_Enter()
dteEffectiveDate.SelStart = 0
End Sub
Private Sub Form_Current()
Dim recClone As DAO.Recordset
'Make a clone of the recordset underlying the form so
'we can move around that without affecting the form's
'recordset
Set recClone = Me.RecordsetClone
'Lock up the data related controls so unplanned
'updates don't happen
' If we are in a new record, disable the <Next> button
'and enable the rest of the buttons and controls
If Me.NewRecord Then
cmdFirst.Enabled = True
cmdPrevious.Enabled = True
cmdNext.Enabled = False
cmdLast.Enabled = True
cmdNew.Enabled = True
dteEffectiveDate.ForeColor = 255 'Signal user we are in Record Add
mode
Exit Sub
End If
'IF we reach here, we know we are not in a new record
'so we can enable the <New> button if the form allows
'new records to be added
cmdNew.Enabled = Me.AllowAdditions
dteEffectiveDate.ForeColor = 0 'Signal user we are in Record Add mode
'But we need to check if there are no records. If so,
'we disable al buttons except for the <New> button
If recClone.RecordCount = 0 Then
cmdFirst.Enabled = False
cmdNext.Enabled = False
cmdPrevious.Enabled = False
cmdLast.Enabled = False
Else
'If there are records, we know that the <First> and
'<Last> buttons will always be enabled, irrespective
'of where we are in the recordset
cmdFirst.Enabled = True
cmdLast.Enabled = True
'Synchronize the current pointer in the two recordsets
recClone.Bookmark = Me.Bookmark
'Next, we meust see if we are on the first record
'If so, we should disable the <Previous> button
recClone.MovePrevious
cmdPrevious.Enabled = Not (recClone.BOF)
recClone.MoveNext
'And then check whether we are on the last record
'If so, we should disable the <Next> button
recClone.MoveNext
cmdNext.Enabled = Not (recClone.EOF)
recClone.MovePrevious
End If
'Check for EffectiveDate relative to current data
If dteEffectiveDate > Date Then
dteEffectiveDate.ForeColor = 4227072 'Date is in future, so set font
color to green
Else
dteEffectiveDate.ForeColor = 0 'Date is current or past, so set
font color to black
End If
'And finally close the cloned recordset
recClone.Close
'Tell others where we are in the recordset
If Not EffectiveDate Then
RaiseEvent CurrentRec(Me)
End If
End Sub
Private Sub cmdUndo_Click()
On Error GoTo Err_cmdUndo_Click
DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
Exit_cmdUndo_Click:
Exit Sub
Err_cmdUndo_Click:
MsgBox Err.Description
Resume Exit_cmdUndo_Click
End Sub
Private Sub cmdDelete_Click()
On Error GoTo Err_cmdDelete_Click
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
Exit_cmdDelete_Click:
Exit Sub
Err_cmdDelete_Click:
MsgBox Err.Description
Resume Exit_cmdDelete_Click
End Sub
Private Sub Form_Load()
Set frmEmp = Forms!frmEmpMaint
End Sub
Private Sub frmEmp_NewEmp(strNewEmp As String, Name As String)
'Initial display should be the current history record
'Build record set clone
Dim recClone As DAO.Recordset
Set recClone = Me.RecordsetClone
' recClone.MoveLast 'Init record count
'Need to scan if there are more than 1 candidate records
If recClone.RecordCount > 1 Then
'Remember that records are in date decending order so the
'first record is most current (or futuristic) history record.
recClone.MoveFirst
'Find history record that is current as of this date
Do
If recClone!EffectiveDate > Date Then
recClone.MoveNext
Else
Me.Bookmark = recClone.Bookmark
Exit Do
End If
Loop Until recClone.EOF = True
End If
If recClone.RecordCount > 0 Then
RaiseEvent NewEmp(Me)
End If
recClone.Close
End Sub
Private Sub txtDeptID_Click()
cboDeptID.Visible = True
cboDeptID.SetFocus
txtDeptID.Visible = False
End Sub
Private Sub txtJobCode_Click()
cboJobCode.Visible = True
cboJobCode.SetFocus
txtJobCode.Visible = False
End Sub
Private Sub cmdSave_Click()
On Error GoTo Err_cmdSave_Click
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Exit_cmdSave_Click:
Exit Sub
Err_cmdSave_Click:
MsgBox Err.Description
Resume Exit_cmdSave_Click
End Sub
---------------------------------------------Cut
Line---------------------------