Issue with Event Timing

Kevin_S

Registered User.
Local time
Today, 11:27
Joined
Apr 3, 2002
Messages
635
Hi Gang - got a little problem here with event timing for Form procedures - hopefully someone might be able to give me a hand with this:

Basically, what I am trying to do is simply enable or disable a command button based on the contents of an id field. This should be simple to do but I'm getting tripped up somewhere and I'm not sure where that is.... so....

I have a form (frmVacancy_Log) that is used to enter hiring info and at the end of the process a user enters an employee ID and clicks a button to open the employee form (frmEmployee). If the employee is already in the system the code checks to make sure they are not already in another position and, if everything looks good, assigns them to the new position OR if they are new the code opens the frmEmployee form and gos to a new record and THEN copies over the New Employee ID and the new Position ID. Here is a snipet of the code for this button that shows the process that takes place for a new employee and the data being copied over to the employee form:
____________________________________________
'''CODE UP HERE'''
If rs.BOF Then
If (MsgBox("No Employee Record Found. Do you wish to create a new record?", vbQuestion + vbYesNo, "No Record Found") = vbYes) Then
DoCmd.OpenForm "frmEmployee"
DoCmd.GoToRecord , , acNewRec
Forms!frmEmployee.EmployeeID = Me.txtEmployeeID
Forms!frmEmployee.PositionID = [Forms]![frmVacancy_Log].[PositionID]
Me.txtEmployeeID = ""
Forms!frmVacancy_Log!txtDateFilled.Value = Date
DoCmd.Close acForm, "frmVacancy_Log"
Else
'''MORE CODE DOWN HERE'''
____________________________________________

This works perfectly fine and does the job that I require HOWEVER, the problem I am running into is that on the frmEmployee form I am trying to check the Position ID for a certain value and then disable/enable a button based on the return of this value in the frmEmployee form's On_Current event. BUT when I open the form with the button from the code above I get the dreaded 'Invalid use of Null' because the form Opens (Runes On_Open Event) then moves to new record (Runs On_Current Event) and trips up.... Here is the code for the frmEmploee Form's On Current Event:
____________________________________________
Dim strCheckCommish As String
strCheckCommish = Mid(Me.PositionID, 7, 1)
If strCheckCommish = 1 Then 'The position is a commisioned position
Me.btnOpenCOD.Enabled = True
Else
Me.btnOpenCOD.Enabled = False
End If
End Sub
____________________________________________

I have tried to using the Nz function - and while that seems to take care of the null problem it also seems to render my code useless since it sees the null as a zero and the code runs even thought the data has not yet been updated in that id field.... It almost seems like I need to time the code on the on_current event to wait for the data to be sent over and then determine if it should enable or disable the button. Anyone have any thoughts on this or maybe I'm just missing something real obvious here (which could be the case I've been staring at this for some time now!)

THanks in advance and sorry so long :D
Kev
 
Why dont you step through the code and see where the problems crops up?

Or post it here and i'll look at it?
 
Nevermind Mark - I got it working this morning. :D

Thanks for talking the time to read this over though and for showing an interest in wanting to help out - I appreciate it!

Thanks,
Kev
 

Users who are viewing this thread

Back
Top Bottom