Sorry about my confusing post. Following is applicable code from the Class Modules of the three forms in question. I have tried to address your questions with notes in the code, and hopefully it's a little clearer. In response to the following:
[CustId] and [LocId] are the primary keys in the Customer and JobLocation tables, but were also used as field names for the foreign key lookup fields in the JobDetail table. (not the best database design, but I was very inexperienced when first starting these databases) The field properties Required (No), and Indexed (Yes, Duplicates Ok) apply to the foreign key fields in JobDetail.BEGINNING OF FORM_ frmJobDetail: CLASS MODULE
Private Sub Form_Activate()
DoCmd.RunCommand acCmdRefresh
End Sub
_______________________________________________________________________________________________
Private Sub Form_Current()
If Me![Intl] = True Then
[SiteCityIntl].Visible = True
[SiteZipIntl].Visible = True
[SiteState].Visible = False
[SiteCity].Visible = False
[SiteZip].Visible = False
Else
[SiteCityIntl].Visible = False
[SiteZipIntl].Visible = False
[SiteState].Visible = True
[SiteCity].Visible = True
[SiteZip].Visible = True
End If
End Sub
_______________________________________________________________________________________________
Private Sub LocId_AfterUpdate()
DoCmd.RunCommand acCmdSaveRecord
DoCmd.SetWarnings False
DoCmd.OpenQuery "qupdJobLocDetail", acNormal, acEdit
DoCmd.SetWarnings True
DoCmd.RunCommand acCmdRefresh
If Me![Intl] = True Then
[SiteCityIntl].Visible = True
[SiteZipIntl].Visible = True
[SiteState].Visible = False
[SiteCity].Visible = False
[SiteZip].Visible = False
Else
[SiteCityIntl].Visible = False
[SiteZipIntl].Visible = False
[SiteState].Visible = True
[SiteCity].Visible = True
[SiteZip].Visible = True
End If
Forms!frmJobDetail!LocId.SetFocus
End Sub
________________________________________________________________________________________________
'This button still works -opens the customer form with linked record if [CustId] has value, opens it in add mode if [CustId] is Null
Private Sub cmdOpenCustFrm_Click()
On Error GoTo Err_cmdOpenCustFrm_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmCustomer"
stLinkCriteria = "[CustId]=" & "'" & Me![CustId] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_cmdOpenCustFrm_Click:
Exit Sub
Err_cmdOpenCustFrm_Click:
MsgBox Err.Description
Resume Exit_cmdOpenCustFrm_Click
End Sub
________________________________________________________________________________________________
'PROBLEM BUTTON -currently opens job location form in add mode if [LocId] is null, but if [LocId] has a value still won't open job location form and show related record. Until I added Bruce's error handler, resulted in following error: '"The OpenForm action was canceled. You used a method of the DoCmd object to carry out an action in Visual Basic, but then clicked Cancel in a dialog box. For example, you used the Close method to close a changed form, then clicked Cancel in the dialog box that asks if you want to save the changes you made to the form."
Private Sub cmdOpenJobLoc_Click() 'THIS STARTS CODE COPIED FROM BRUCE
On Error GoTo cmdOpenJobLoc_Click_Err
'Check for Null value before opening form
If Not IsNull(Me![LocId]) Then 'BEFORE ADDING IsNull CODING NULL [LocId] PRODUCED ERROR "Syntax error (missing operator)in query expression '[LocId]='."
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmJobLocation"
stLinkCriteria = "[LocId]=""" & Me![LocId] & """"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else 'Location ID is Null
'FOLLOWING CODE IS MINE REPLACING BRUCE'S (MsgBox "The Location ID field is empty." GoTo Exit_cmdOpenJobLoc_Click)
DoCmd.OpenForm "frmJobLocation", , , , acAdd, acNormal
End If
'BACK TO BRUCE'S CODE
cmdOpenJobLoc_Click_Exit:
Exit Sub
cmdOpenJobLoc_Click_Err:
If Err.Number = 2501 Then 'Operation cancelled
Resume Next
Else
MsgBox "Error: " & Err.Number & " - " & Err.Description
Resume cmdOpenJobLoc_Click_Exit
End If 'THIS END IF WAS NOT IN THE CODE FROM THE POST
'
http://communities2.microsoft.com/c...ding&mid=85c6ba1d-8ac2-4b62-80e3-268c665bac0c
End Sub 'END OF BRUCE'S CODE
________________________________________________________________________________________________
END OF FORM_ frmJobDetail: CLASS MODULEBEGINNING OF FORM_ frmCustomer: CLASS MODULE
________________________________________________________________________________________________
Private Sub Form_Current()
If Me![Intl] = True Then
[CustZipIntl].Visible = True
[CustMainPhoneIntl].Visible = True
[CustMainFaxIntl].Visible = True
[CustCityIntl].Visible = True
[CustSt].Visible = False
[CustCity].Visible = False
[CustZip].Visible = False
[CustMainPhone].Visible = False
[CustMainFax].Visible = False
Else
[CustZipIntl].Visible = False
[CustMainPhoneIntl].Visible = False
[CustMainFaxIntl].Visible = False
[CustCityIntl].Visible = False
[CustCity].Visible = True
[CustSt].Visible = True
[CustZip].Visible = True
[CustMainPhone].Visible = True
[CustMainFax].Visible = True
End If
End Sub
________________________________________________________________________________________________
Private Sub Form_Deactivate()
DoCmd.RunCommand acCmdSaveRecord
DoCmd.RunCommand acCmdRefresh
End Sub
________________________________________________________________________________________________
END OF FORM_ frmCustomer: CLASS MODULEBEGINNING OF FORM_ frmJobLocation: CLASS MODULE
________________________________________________________________________________________________
Private Sub Form_Current()
If Me![Intl] = True Then
[SiteZipIntl].Visible = True
[SitePhoneIntl].Visible = True
[SiteFaxIntl].Visible = True
[SiteCityIntl].Visible = True
[SiteState].Visible = False
[SiteCity].Visible = False
[SiteZip].Visible = False
[SitePhone].Visible = False
[SiteFax].Visible = False
Else
[SiteZipIntl].Visible = False
[SitePhoneIntl].Visible = False
[SiteFaxIntl].Visible = False
[SiteCityIntl].Visible = False
[SiteCity].Visible = True
[SiteState].Visible = True
[SiteZip].Visible = True
[SitePhone].Visible = True
[SiteFax].Visible = True
End If
End Sub
________________________________________________________________________________________________
Private Sub Form_Deactivate()
DoCmd.RunCommand acCmdRefresh
End Sub
________________________________________________________________________________________________
END OF FORM_ frmJobLocation: CLASS MODULE