Ken,
I'm not running code in any of the subform control's events, nor am I
running any code in the subform form's OnCurrent event. Again, thanks for
taking the time to review the code and make those suggestions.
Paul
Just in case it would be of any interest, here is the code from the Main
Form's module:
Option Explicit
Option Compare Database
Private Sub cboSelectProject_Enter()
Me.AllowEdits = True
Me!frmProjectContactsSub.Form.AllowEdits = True
Me!ctlLeases.Form.AllowEdits = True
End Sub
Private Sub cboSelectProject_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[ProjectID] = " & Str(Nz(Me![cboSelectProject], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub
Function authorization_check()
'Determine if the user is a member of the project and set the authorization
for form and both subforms.
'If we're just adding a new record to the form, don't run this function
If Me.RecordsetClone.RecordCount < 2 Then Exit Function
'begin authorization check
Dim db As Database
Dim rs As Recordset
Dim strSql As String
Set db = CurrentDb
strSql = "SELECT tblProject.ProjectID, tblContacts.osUserName FROM
tblProject INNER JOIN (tblContacts INNER JOIN tblProjectContact ON
tblContacts.ContactID = tblProjectContact.ContactID) ON tblProject.ProjectID
= tblProjectContact.ProjectID WHERE (tblProject.ProjectID = " &
Forms!frmProjects!txtProjectID & ") AND tblContacts.osUserName =
fosUserName();"
Set rs = db.OpenRecordset(strSql, dbOpenDynaset)
If rs.RecordCount > 0 Then
authorization_check = True
Else
authorization_check = False
End If
Me.AllowEdits = authorization_check
Me.AllowDeletions = authorization_check
Me!frmProjectContactsSub.Form.AllowEdits = authorization_check
Me!frmProjectContactsSub.Form.AllowAdditions = authorization_check
Me!frmProjectContactsSub.Form.AllowDeletions = authorization_check
Me!ctlLeases.Form.AllowEdits = authorization_check
Me!ctlLeases.Form.AllowAdditions = authorization_check
Me!ctlLeases.Form.AllowDeletions = authorization_check
'end authorization check
End Function
Private Sub City_AfterUpdate()
Me!County = DLookup("County", "tblCityZip", "City = '" & City & "'")
If Len(Nz(Me!cboAgency)) > 0 And Len(Nz(Me!City)) > 0 And
Len(Nz(Me!txtProjectID)) > 0 Then
Me!txtProjectName = Me!cboAgency & "_" & Me!City & "_" &
Me!txtProjectID
End If
Me!cboSelectProject.Requery
Me.Repaint
fRequeryAll
End Sub
Private Sub cmd_Close_without_saving_Click()
Me.Undo
DoCmd.Close
End Sub
Private Sub cmd_open_frmProjectNotes_Click()
On Error GoTo Err_cmd_open_frmProjectNotes_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmProjectNotes"
stLinkCriteria = "[ProjectID]=" & Me![ProjectID]
If authorization_check = True Then
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
Me.Undo
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormReadOnly
End If
Exit_cmd_open_frmProjectNotes_Click:
Exit Sub
Err_cmd_open_frmProjectNotes_Click:
MsgBox Err.Description
Resume Exit_cmd_open_frmProjectNotes_Click
End Sub
Private Sub cmd_Save_and_Close_Click()
If authorization_check = True Then
DoCmd.RunCommand acCmdSaveRecord
Else
Me.Undo
End If
DoCmd.Close
End Sub
Private Sub cmdAddNewContact_Click()
On Error GoTo ErrorTrap
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frm_Name_Lookup"
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormAdd
''Hide combo box and "Select another contact" label
' Forms!frmContacts!cboSelectContact.Visible = False
' Forms!frmContacts!lbl_Enable_cboSelectContact.Visible = False
Exit Sub
ErrorTrap:
MsgBox "The following error has occurred: " & vbCr & vbCr & _
Err.Number & " - " & Err.Description & vbCr & vbCr & _
"Press 'Alt + Print Scrn' to copy this notice into an email message to
the database administrator.", vbOKOnly, "Error Notice"
Resume Next
End Sub
Private Sub cmdAddNewProject_Click()
On Error GoTo ErrorTrap
Dim stDocName As String
Dim stLinkCriteria As String
DoCmd.Close
stDocName = "frm_New_Project"
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormAdd
Exit Sub
ErrorTrap:
MsgBox "The following error has occurred: " & vbCr & vbCr & _
Err.Number & " - " & Err.Description & vbCr & vbCr & _
"Press 'Alt + Print Scrn' to copy this notice into an email message to
the database administrator.", vbOKOnly, "Error Notice"
Resume Next
End Sub
Private Sub cmdSetFileLocation_Click()
'Build the File Location path from Agency and City
'check to make sure required fields are populated
If Len(Nz(Forms!frmProjects!txtProjectName)) = 0 Then
MsgBox "Enter a Project Name", vbOKOnly, "Project Name Missing"
Exit Sub
End If
If Len(Nz(Forms!frmProjects!cboAgency)) = 0 Then
MsgBox "Enter the Agency", vbOKOnly, "Agency Missing"
Exit Sub
End If
If Len(Nz(Forms!frmProjects!City)) = 0 Then
MsgBox "Enter the City", vbOKOnly, "City Missing"
Exit Sub
End If
Forms!frmProjects!FileLocation = Forms!frmProjects!txtProjectName &
"#M:\Leasing-And-Design\Jobs\" & Forms!frmProjects!cboAgency & "\" &
Forms!frmProjects!City & "#"
End Sub
Private Sub form_afterupdate()
fRequeryAll
End Sub
'Private Sub Form_BeforeUpdate(Cancel As Integer)
' Me!txtLastUpdate = Date
' Me!txtUpdatedBy = fOSUserName
'End Sub
Sub Form_Current()
If IsLoaded("frm_new_project") Then Exit Sub
Me!cboSelectProject = Me!ProjectID
Me!txtFocusTrap.SetFocus
authorization_check
If Len(Nz(Me!County)) = 0 Then Me!Label63.Visible = False Else
Me!Label63.Visible = True
If Len(Nz(Me!cboAgencyContact)) = 0 Then Me!Label93.Visible = False Else
Me!Label93.Visible = True
If Len(Nz(Me!DateInactive)) = 0 Then Me!Label97.Visible = False Else
Me!Label97.Visible = True
End Sub
Private Sub Form_Load()
'no need to perform any of the following procedures
' if the form was opened from frm_new_project.
If IsLoaded("frm_new_project") Then Exit Sub
'Go to the same record that was current
' the last time the form was open.
Dim varID As Variant
'MsgBox "form_load"
'Return to last project
varID = DLookup("Value", "tblSys", "[Variable] = 'frmProjectsLast'")
If IsNumeric(varID) Then
With Me.RecordsetClone
.FindFirst "[ProjectID] = " & varID
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End If
End With
End If
authorization_check
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Call the function "Set_frmProjectsLast"
' to store the ID of the current record, so the form will open
' to that same record the next time it opens.
Set_frmProjectsLast
End Sub
Private Sub cmd_close_form_Click()
On Error GoTo Err_cmd_close_form_Click
DoCmd.Close
Exit_cmd_close_form_Click:
Exit Sub
Err_cmd_close_form_Click:
MsgBox Err.Description
Resume Exit_cmd_close_form_Click
End Sub
Private Sub Notes_DblClick(Cancel As Integer)
On Error GoTo Err_Notes_DblClick
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmProjectNotes"
stLinkCriteria = "[ProjectID]=" & Me![ProjectID]
If authorization_check = True Then
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
Me.Undo
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormReadOnly
End If
Exit_Notes_DblClick:
Exit Sub
Err_Notes_DblClick:
MsgBox Err.Description
Resume Exit_Notes_DblClick
End Sub
Private Sub Status_AfterUpdate()
If Me!Status <> "Active" Then
Me!DateInactive = Date
Else
Me!DateInactive = ""
End If
End Sub
Private Sub Zip_AfterUpdate()
If Not IsNull(Me!Zip) Then
Me!City = DLookup("City", "tblCityZip", "Zip = " & Zip)
Me!State = DLookup("State", "tblCityZip", "Zip = " & Zip)
Me!County = DLookup("County", "tblCityZip", "City = '" & City & "'")
End If
If Len(Nz(Me!cboAgency)) > 0 And Len(Nz(Me!City)) > 0 And
Len(Nz(Me!txtProjectID)) > 0 Then
Me!txtProjectName = Me!cboAgency & "_" & Me!City & "_" &
Me!txtProjectID
End If
Me!cboSelectProject.Requery
Me.Repaint
fRequeryAll
End Sub