Here is my code...
Private Sub Job_NotInList(NewData As String, Response As Integer)
'ask user if they want to add job to list
Ans = MsgBox("Job not in list. Do you want to add it?", vbYesNo Or
vbQuestion, "Add Job to list?")
'if no, return them to list
If Ans = vbNo Then Response = acDataErrContinue: Exit Sub
'if yes, ask for a description of job before adding to Jobs table
tempdesc = InputBox("Enter a description for this job.", "Add job to
list", "Enter job description")
'if user presses cancel or enters blank, exit
If tempdesc = "" Then
Response = acDataErrContinue
Exit Sub
End If
Add new job to list
DoCmd.SetWarnings (False)
DoCmd.RunSQL ("INSERT INTO Jobs ( JobNum, JobDesc ) SELECT " & NewData
& " AS JobNum, '" & tempdesc & "' AS JobDesc")
DoCmd.SetWarnings (True)
'tell access the new job has been added to the table
Response = acDataErrAdded
End Sub
***IT THEN GOES TO THE AfterUpdate EVENT OF THE SAME CONTROL
Private Sub Job_AfterUpdate()
'set permission and cost object to null to avoid fields that look
blank but
'contain info from previously selected jobs
Me.CostPermission = Null
Me.CostObject = Null
Refresh
'set default client #
Set rstemp = CurrentDb.OpenRecordset("SELECT * FROM CostPermissions
WHERE JobID = " & Me.Job & " AND DefaultPer = True")
If rstemp.EOF = True Then GoTo ChooseSingleCostCode
rstemp.MoveLast
If rstemp.RecordCount = 0 Then Exit Sub
Me.CostPermission = rstemp.Fields("PerID")
ChooseSingleCostCode:
'if only one cost code on job, select it for user
Set rstemp = CurrentDb.OpenRecordset("SELECT CostObjID FROM
CostObjects WHERE JobID = " & Me.Job)
***WITHOUT EXPLAINING MUCH ABOUT MY DB, THE FOLLOWING STATEMENT
RETURNS FALSE, AS IT SHOULD
***BUT THEN IT GOES STRAIGHT INTO THE SUB BELOW, WHICH IS THE SUB FOR
THE DEFAULT BUTTON OF THE FORM
If rstemp.EOF = True Then Exit Sub
rstemp.MoveLast
If rstemp.RecordCount = 1 Then
Me.CostObject = rstemp.Fields("CostObjID")
End If
rstemp.Close
Refresh
End Sub
***wHEN THE AfterUpdate SUB IS DONE, IT GOES INTO THE BELOW SUB,
***THIS IS THE SUB FOR THE DEFAULT BUTTON ON THE FORM
Private Sub butADD_Click()
'add new entry to log
'__/~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\_
'-------------DATA VALIDATION--------------
'--\~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/-
'check if item is selected
If IsNull(Me.ChooseItem) = True Then
MsgBox "Please select " & Me.ItemTypeFilter & " from the
list.", vbInformation, "Make selection"
Exit Sub
End If
**THERE IS MORE BELOW THIS BUT THIS PROBLEM ENDS WITH THIS FIRST IF
STATEMENT
I don't understand how a control could call the sub of the default
control on a form without me coding it?
This sequence is strange