Ok, so I have looked High and low to find an answer to my problem. I'm fairly new to using recordsets.
Maybe, or more than likely, in the wrong places.
I am an Access 2000 Developer.
I have a form for entering course details with the underlying table
TBL_Course.
The form which is used to enter data is
FRM_Course
On it there is a combo box which is used to display the tutors name. it uses the tutor ID as the bound data for the combo box. The tutor data is sourced from the table
TBL_Tut
What I want
To be able to programmatically add a new tutor to the underlying tutor table of the combo box, when a new name is typed which is not in the list.
The underlying table only has these two fields. Tutor_No (autonumber) and Tut_Name (text)
The problem
It gives me an error message when this code runs on the not in list event of the combo box.
the error is type mismatch, I think its trying to add this newdata to the autonumber field. How do I get it to fill in the autonumber and enter in my text(newdata) as the tutors name.
the code I am using is given below.
-------------------
start of code
------------------------------
Private Sub Tutor_NotInList(NewData As String, Response As Integer)
Dim msg As String
Dim rs As Recordset
Dim db As Database
msg = NewData & " is not a tutor held in the database" & vbCr & _
"Would you like add " & NewData & " to the database" & vbCr & vbCr & _
" Click Yes to Add or NO to Re-Type"
If MsgBox(msg, vbYesNo + vbExclamation, "Unknown tutor name " & NewData) = vbNo Then
SendKeys "{esc}"
Response = acDataErrContinue
Exit Sub
Else
Set db = CurrentDb
Set rs = db.OpenRecordset("TBL_Tut", dbOpenDynaset)
rs.AddNew
rs!Tut_Name = NewData
rs.Update
Response = acDataErrAdded
Set db = Nothing
rs.Close
Set rs = Nothing
db.Close
End If
End Sub
any help would be appreciated.
And if i'm doing the close rs and db thing wrongly could someone let me know. I'm just guessing that it should be the way I have done it i.e.
Set db = Nothing
rs.Close
Set rs = Nothing
db.Close
Thanks in advance
Idd
Maybe, or more than likely, in the wrong places.
I am an Access 2000 Developer.
I have a form for entering course details with the underlying table
TBL_Course.
The form which is used to enter data is
FRM_Course
On it there is a combo box which is used to display the tutors name. it uses the tutor ID as the bound data for the combo box. The tutor data is sourced from the table
TBL_Tut
What I want
To be able to programmatically add a new tutor to the underlying tutor table of the combo box, when a new name is typed which is not in the list.
The underlying table only has these two fields. Tutor_No (autonumber) and Tut_Name (text)
The problem
It gives me an error message when this code runs on the not in list event of the combo box.
the error is type mismatch, I think its trying to add this newdata to the autonumber field. How do I get it to fill in the autonumber and enter in my text(newdata) as the tutors name.
the code I am using is given below.
-------------------
start of code
------------------------------
Private Sub Tutor_NotInList(NewData As String, Response As Integer)
Dim msg As String
Dim rs As Recordset
Dim db As Database
msg = NewData & " is not a tutor held in the database" & vbCr & _
"Would you like add " & NewData & " to the database" & vbCr & vbCr & _
" Click Yes to Add or NO to Re-Type"
If MsgBox(msg, vbYesNo + vbExclamation, "Unknown tutor name " & NewData) = vbNo Then
SendKeys "{esc}"
Response = acDataErrContinue
Exit Sub
Else
Set db = CurrentDb
Set rs = db.OpenRecordset("TBL_Tut", dbOpenDynaset)
rs.AddNew
rs!Tut_Name = NewData
rs.Update
Response = acDataErrAdded
Set db = Nothing
rs.Close
Set rs = Nothing
db.Close
End If
End Sub
any help would be appreciated.
And if i'm doing the close rs and db thing wrongly could someone let me know. I'm just guessing that it should be the way I have done it i.e.
Set db = Nothing
rs.Close
Set rs = Nothing
db.Close
Thanks in advance
Idd