Attached is my code (Copied from the internet and modified) for an Access 2000 database. I want to add a new "Analyst" to a table called "Financial_Analyst". I am using a combo box that lists the current Analysts, but if one is not there I would like the user to be able to add an Analyst. The combo box is on another form where all the rest of the data for the project is entered. So I put the code in the Event Procedure for "NotInList". THe problem is .. I keep getting this message [Run Time Error 13, Type Mismatch] What does this mean? THe line it craps out on is: Set rstAnalyst=db.OpenRecordset(sqlFinancial_Analyst, dbOpenDynaset)
Thanks for your help.
Private Sub Financial_Analyst_NotInList(NewData As String, Response As Integer)
'Suppress the default error message
Response = acDataErrContinue
'Prompt user to verify if they wish to add new value
If MsgBox("The Financial Analyst " & NewData & " is not in list. Add it?", vbYesNo) = vbYes Then
'Set Response arguement to indicate that data is being added
'Open Recordset of the Financial_Analyst Table
Dim db As Database
Dim rstAnalyst As Recordset
Dim Financial_Analyst As String
Set db = CurrentDb()
sqlFinancial_Analyst = "Select * From Financial_Analyst"
Set rstAnalyst = db.OpenRecordset(sqlFinancial_Analyst, dbOpenDynaset)
'Add new Analyst with the variable that is stored in the variable NewData
rstAnalyst.AddNew
rstAnalyst![Analyst] = NewData
rstAnalyst.Update
'Inform the combo box that the desired item has been added to the list
Response = acDataErrAdded
rstAnalyst.Close 'Close the recordset
End If
End Sub
Same Circus, Different Clowns
Thanks for your help.
Private Sub Financial_Analyst_NotInList(NewData As String, Response As Integer)
'Suppress the default error message
Response = acDataErrContinue
'Prompt user to verify if they wish to add new value
If MsgBox("The Financial Analyst " & NewData & " is not in list. Add it?", vbYesNo) = vbYes Then
'Set Response arguement to indicate that data is being added
'Open Recordset of the Financial_Analyst Table
Dim db As Database
Dim rstAnalyst As Recordset
Dim Financial_Analyst As String
Set db = CurrentDb()
sqlFinancial_Analyst = "Select * From Financial_Analyst"
Set rstAnalyst = db.OpenRecordset(sqlFinancial_Analyst, dbOpenDynaset)
'Add new Analyst with the variable that is stored in the variable NewData
rstAnalyst.AddNew
rstAnalyst![Analyst] = NewData
rstAnalyst.Update
'Inform the combo box that the desired item has been added to the list
Response = acDataErrAdded
rstAnalyst.Close 'Close the recordset
End If
End Sub
Same Circus, Different Clowns