Sorry Robert, still no joy. I did as you suggested and placed a command button on Form2 (FrmCompDetails). Then, I entered an unknown number in the TxtServiceNumber combobox on FrmTeamData . The Message box came up and, when I pressed the Yes button I received a Run-time error message:
Run-Time Error '-2147352567 (80020009) You can't assign a value to this object.
I clicked debug and the code for the OnOpen event on FrmCompDetails appeared - highlighted in yellow.
I closed the code and then exited the original form (FrmTeamData) and received the following message:
The text you entered isn't an item in the list. Select an item from the list or enter text that matches one of the listed items.
The set-up is as follows:
The main form (FrmTeamData) is based on one table (TblCompetitor). In this form, the combobox TxtServiceNumber AfterUpdate event looks up the entered number in a second table (TblCompDetails) and, if the service number is in that table, extracts the competor's name and initials and enters them into TblCompetitor.
If the service number is not recognised, the message box appears and, when Yes is pressed, FrmCompDetails opens. This form is based on TblCompDetails and has three text boxes - TxtServiceNumber, TxtName and TxtInitials. These three are completed, the form is then closed and the new details appear in FrmTeam Data.
What I would like to happen is that, having entered the unrecognised service number on FrmTeamData, the message box appears, followed by FrmCompDetails which opens with the unrecognised service number in the TxtServiceNumber text box. The name and initials can then be entered, the form closed and the full details will then appear in FrmTeamData. This way, the service number is only entered once.
The codes I have so far are as follows:
1 FrmTeamData - TxtServiceNumber Not in list:
Code:
Private Sub Service_Number_NotInList(NewData As String, Response As Integer)
On Error GoTo Err_Service_Number_NotInList
'Service Number not recognised
Dim intAnswer As Integer
intAnswer = MsgBox("Add Competitor Details?", vbYesNo, vbQuestion)
If intAnswer = vbYes Then
DocName = "FrmCompDetails"
DoCmd.RunCommand acCmdUndo
DoCmd.OpenForm DocName, acNormal, , , acFormEdit, acDialog, NewData
Response = acDataErrAdded
Else
Response = acDataErrContinue
End If
Exit_Service_Number_NotInList:
Exit Sub
Err_Service_Number_NotInList:
MsgBox Err.Description
Resume Exit_Service_Number_NotInList:
End Sub
2 FrmCompDetails - On Open:
Code:
Private Sub Form_Open(Cancel As Integer)
Me.TxtServiceNumber = Me.OpenArgs
End Sub
[code]
3 FrmCompDetails - New Command Button:
[code]
Private Sub Command5_Click()
On Error GoTo Err_Command5_Click
Dim strSQL As String
strSQL = "Insert into TblCompDetails ('" & Me.TxtServiceNumber & "');"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
'Screen.PreviousControl.SetFocus
' DoCmd.FindNext
Exit_Command5_Click:
Exit Sub
Err_Command5_Click:
MsgBox Err.Description
Resume Exit_Command5_Click
End Sub
[code]
For ease of use, I would prefer not to have to use the command button but if this is the only way, so be it.
I hope this explains the set-up more clearly and that it will help you to resolve my problem.
If you think that your example would help, my email address is john@jdraper.net. If it would help you further, I could make an extract of my database and email that to you. Please let me know.
Best Regards
John