Access 2002 issue:
I have a combo Box with the Limit To List property set to yes. I got the following code here:
*************************************
*************************************
Private Sub Combo86_BeforeUpdate(Cancel As Integer)
' Display message if contactID combo box is blank.
Dim strMsg As String, strTitle As String
Dim intStyle As Integer
If IsNull(Me!Combo86) Or Me!Combo86 = "" Then
strMsg = "You must pick a value from the Contact list."
strTitle = "Contact Required"
intStyle = vbOKOnly
MsgBox strMsg, intStyle, strTitle
Cancel = True
End If
End Sub
*******************************
Private Sub Combo86_NotInList(NewData As String, Response As Integer)
Dim Db As Database
Dim Rs As Recordset
Dim Msg As String
Dim CR As String
CR = Chr$(13)
' Exit this subroutine if the combo box was cleared.
If NewData = "" Then Exit Sub
' Confirm that the user wants to add the new customer.
Msg = "'" & NewData & "' is not in the list." & CR & CR
Msg = Msg & "Do you want to add it?"
If MsgBox(Msg, vbQuestion + vbYesNo) = vbNo Then
' If the user chose not to add a customer, set the Response
' argument to suppress an error message and undo changes.
Response = acDataErrContinue
' Display a customized message.
MsgBox "Please try again."
Else
' If the user chose to add a new customer, open a recordset
' using the Customers table.
Set Db = CurrentDb
Set Rs = Db.OpenRecordset("contactTbl", DB_OPEN_TABLE)
' Let code execution continue if a run-time error occurs.
On Error Resume Next
' Create a new record.
Rs.AddNew
' Assign the NewData argument to the Last Name field.
Rs![Last Name] = NewData
' Save the record.
Rs.Update
If Err Then
' If a run-time error occurred while attempting to add a new
' record, set the Response argument to suppress an error
' message and undo changes.
Response = acDataErrContinue
' Display a customized message.
MsgBox Error$ & CR & CR & "Please try again.", vbExclamation
Else
' If a run-time error did not occur, set Response argument
' to indicate that new data is being added.
Response = acDataErrAdded
End If
End If
End Sub
****************************************
****************************************
PROBLEM:
Some times, this code works. Other times, I get the following error message:
"The current field must match the join key '?' in the table that serves as the 'one' side of the one-to-many relationship..."
If I re-create the form, the Combo Box works fine for a while.
So far, I don't see this problem in Access 97.
Thanks,
John
I have a combo Box with the Limit To List property set to yes. I got the following code here:
*************************************
*************************************
Private Sub Combo86_BeforeUpdate(Cancel As Integer)
' Display message if contactID combo box is blank.
Dim strMsg As String, strTitle As String
Dim intStyle As Integer
If IsNull(Me!Combo86) Or Me!Combo86 = "" Then
strMsg = "You must pick a value from the Contact list."
strTitle = "Contact Required"
intStyle = vbOKOnly
MsgBox strMsg, intStyle, strTitle
Cancel = True
End If
End Sub
*******************************
Private Sub Combo86_NotInList(NewData As String, Response As Integer)
Dim Db As Database
Dim Rs As Recordset
Dim Msg As String
Dim CR As String
CR = Chr$(13)
' Exit this subroutine if the combo box was cleared.
If NewData = "" Then Exit Sub
' Confirm that the user wants to add the new customer.
Msg = "'" & NewData & "' is not in the list." & CR & CR
Msg = Msg & "Do you want to add it?"
If MsgBox(Msg, vbQuestion + vbYesNo) = vbNo Then
' If the user chose not to add a customer, set the Response
' argument to suppress an error message and undo changes.
Response = acDataErrContinue
' Display a customized message.
MsgBox "Please try again."
Else
' If the user chose to add a new customer, open a recordset
' using the Customers table.
Set Db = CurrentDb
Set Rs = Db.OpenRecordset("contactTbl", DB_OPEN_TABLE)
' Let code execution continue if a run-time error occurs.
On Error Resume Next
' Create a new record.
Rs.AddNew
' Assign the NewData argument to the Last Name field.
Rs![Last Name] = NewData
' Save the record.
Rs.Update
If Err Then
' If a run-time error occurred while attempting to add a new
' record, set the Response argument to suppress an error
' message and undo changes.
Response = acDataErrContinue
' Display a customized message.
MsgBox Error$ & CR & CR & "Please try again.", vbExclamation
Else
' If a run-time error did not occur, set Response argument
' to indicate that new data is being added.
Response = acDataErrAdded
End If
End If
End Sub
****************************************
****************************************
PROBLEM:
Some times, this code works. Other times, I get the following error message:
"The current field must match the join key '?' in the table that serves as the 'one' side of the one-to-many relationship..."
If I re-create the form, the Combo Box works fine for a while.
So far, I don't see this problem in Access 97.
Thanks,
John