R
Ruth
Hi,there
I just started with ACCESS coding. I tried to use a combo
box to input BASEID but when I move mouse to input
BASEDESC it incurs "keyword duplicate" error. The code is
as follows:
Private Sub BASEID_NotInList(NewData As String, Response
As Integer)
Dim db As DAO.Database
Dim Rs As DAO.Recordset
Dim Msg As String
On Error GoTo Err_BASEID_NotInList
If NewData = "" Then Exit Sub
Msg = "'" & NewData & "' is not in the list." & vbCr
& vbCr
Msg = Msg & "Do you want to add it?"
If MsgBox(Msg, vbQuestion + vbYesNo) = vbNo Then
Response = acDataErrContinue
MsgBox "Please try again."
Else
Set db = CurrentDb
Set Rs = db.OpenRecordset("BASES", dbOpenDynaset)
Rs.FindFirst BuildCriteria("BASEID", dbText,
NewData)
Do Until Rs.NoMatch
NewData = InputBox("BASEID " & NewData & "
already exists." & _
vbCr & vbCr & Msg, NewData & " Already
Exists")
Rs.FindFirst BuildCriteria("BASEID", dbText,
NewData)
Loop
Rs.AddNew
Rs![BASEID] = NewData
Rs![BASEDESC] = ""
Rs.Update
Response = acDataErrAdded
End If
Exit_BASEID_NotInList:
Exit Sub
Err_BASEID_NotInList:
MsgBox Err.Description
Response = acDataErrContinue
End Sub
Thanks a lot
I just started with ACCESS coding. I tried to use a combo
box to input BASEID but when I move mouse to input
BASEDESC it incurs "keyword duplicate" error. The code is
as follows:
Private Sub BASEID_NotInList(NewData As String, Response
As Integer)
Dim db As DAO.Database
Dim Rs As DAO.Recordset
Dim Msg As String
On Error GoTo Err_BASEID_NotInList
If NewData = "" Then Exit Sub
Msg = "'" & NewData & "' is not in the list." & vbCr
& vbCr
Msg = Msg & "Do you want to add it?"
If MsgBox(Msg, vbQuestion + vbYesNo) = vbNo Then
Response = acDataErrContinue
MsgBox "Please try again."
Else
Set db = CurrentDb
Set Rs = db.OpenRecordset("BASES", dbOpenDynaset)
Rs.FindFirst BuildCriteria("BASEID", dbText,
NewData)
Do Until Rs.NoMatch
NewData = InputBox("BASEID " & NewData & "
already exists." & _
vbCr & vbCr & Msg, NewData & " Already
Exists")
Rs.FindFirst BuildCriteria("BASEID", dbText,
NewData)
Loop
Rs.AddNew
Rs![BASEID] = NewData
Rs![BASEDESC] = ""
Rs.Update
Response = acDataErrAdded
End If
Exit_BASEID_NotInList:
Exit Sub
Err_BASEID_NotInList:
MsgBox Err.Description
Response = acDataErrContinue
End Sub
Thanks a lot