Hi,
I'm working on a project which contains three forms:
The first form ("frmMain") contains a number of buttons, one of which serves to open the second form in DataEntry mode.
The second form ("frmAudits") contains a few text-, combo- and checkboxes, all bound to the table tblAudits. It also contains a listbox and three buttons, cmdAdd, cmdEdit and cmdDelete. The listbox is unbound. Its rowsource is programmatically set to a query for all related records in another table (tblIssues), i.e. records with a Audit_foreign_key matching the ID of the current record in tblAudits.
When the user clicks cmdEdit, the third userform ("frmIssues") is opened to the record selected in the listbox:
When the user clicks cmdAdd, the third userform is opened in DataEntry mode:
For some reason, the behavior of the cmdAdd button is inconsistent. Sometimes, I open the second form, click the button - either right away or after doing some other action on the form, like completing a textbox - and the third form will load in DataEntry mode as expected. But other times, I get the "Need to fix this!" error message, because the me.ID that gets passed to the third form is Null. Yet clicking the button a second time, even right after getting the error, always works. Also, when i step through the code in debugging mode, the issue never presents itself.
Any thoughts on what is causing this?
I'm working on a project which contains three forms:
The first form ("frmMain") contains a number of buttons, one of which serves to open the second form in DataEntry mode.
The second form ("frmAudits") contains a few text-, combo- and checkboxes, all bound to the table tblAudits. It also contains a listbox and three buttons, cmdAdd, cmdEdit and cmdDelete. The listbox is unbound. Its rowsource is programmatically set to a query for all related records in another table (tblIssues), i.e. records with a Audit_foreign_key matching the ID of the current record in tblAudits.
When the user clicks cmdEdit, the third userform ("frmIssues") is opened to the record selected in the listbox:
Code:
DoCmd.OpenForm "frmIssues", , , "[Audit_foreign_key]=" & Me.lstIssues.Value, acFormEdit, acDialog
Me.AllowDeletions = False
Me.AllowAdditions = False
Me.AllowEdits = True
When the user clicks cmdAdd, the third userform is opened in DataEntry mode:
Code:
[If Me.NewRecord Then Me.Dirty = False 'not doing this results in an error message on frmIssues, because of referential integrity. Is there a better way to solve this?
DoCmd.OpenForm "frmIssues", , , , acFormAdd, acDialog, Me.ID/CODE]
The "Me.ID" serves to pass the ID of the current record in tblAudit to be used in the Load event of the third form:
[CODE]If Me.DataEntry Then
If Me.OpenArgs <> vbNullString Then
Me.Controle_FK = Me.OpenArgs
Else
MsgBox "An unexpected error has occurred.", vbCritical + vbOKOnly, "Need to fix this!"
DoCmd.Close acForm, Me.Name, acSaveNo
End If
Else
Me.AllowDeletions = False
Me.AllowAdditions = False
Me.AllowEdits = True
End If
For some reason, the behavior of the cmdAdd button is inconsistent. Sometimes, I open the second form, click the button - either right away or after doing some other action on the form, like completing a textbox - and the third form will load in DataEntry mode as expected. But other times, I get the "Need to fix this!" error message, because the me.ID that gets passed to the third form is Null. Yet clicking the button a second time, even right after getting the error, always works. Also, when i step through the code in debugging mode, the issue never presents itself.
Any thoughts on what is causing this?