HI, all.
I have problems in my form. Please advise for me.
I have a combobox which has 3 fields: StudentID(column 0), StudntName (column 1), StudentAddress (column 2).
When I put studnetID, if it is in the list then it's name and address fields are automatically filled (It works.). If the ID is not in the list, I want to get message box ( do you want to add the new ID on the list?) and add the ID on the student table.
I found this code:
Private Sub Combo292_NotInList(NewData As String, Response As Integer)
On Error GoTo myError
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("Students", dbOpenDynaset)
If vbYes = MsgBox("This Entry is not in list. Do you wish to add " _
& NewData & " as a new StudnetID?", _
vbYesNoCancel + vbDefaultButton2, _
"New StudnetID") Then
rst.AddNew
rst!StudentID = NewData
rst.Update
Response = acDataErrAdded
Else
Response = acDataErrContinue
End If
leave:
If Not rst Is Nothing Then
rst.Close: Set rst = Nothing
End If
Exit Sub
myError:
MsgBox "Error " & Err.Number & ": " & Error$
Resume leave
End Sub
Problem 1: this code does not work. the new ID is added on the table, but the message box doesn't pop up when I put a new studentID.
Problem 2: although I would like to put each digit of studentID one by one when I put student ID, the first ID number abruptly pops up and if I want other number to put, I need to delete the first studentID. (i.e. if I want to put 0004, it automatically pops up 0001(the first ID) when I put first '0' on the box. then I should delete the '001' and then put '004'.)
Can I put the studentID one by one?
Please forgive my terrible english.
Can anybody help me out?
I have problems in my form. Please advise for me.
I have a combobox which has 3 fields: StudentID(column 0), StudntName (column 1), StudentAddress (column 2).
When I put studnetID, if it is in the list then it's name and address fields are automatically filled (It works.). If the ID is not in the list, I want to get message box ( do you want to add the new ID on the list?) and add the ID on the student table.
I found this code:
Private Sub Combo292_NotInList(NewData As String, Response As Integer)
On Error GoTo myError
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("Students", dbOpenDynaset)
If vbYes = MsgBox("This Entry is not in list. Do you wish to add " _
& NewData & " as a new StudnetID?", _
vbYesNoCancel + vbDefaultButton2, _
"New StudnetID") Then
rst.AddNew
rst!StudentID = NewData
rst.Update
Response = acDataErrAdded
Else
Response = acDataErrContinue
End If
leave:
If Not rst Is Nothing Then
rst.Close: Set rst = Nothing
End If
Exit Sub
myError:
MsgBox "Error " & Err.Number & ": " & Error$
Resume leave
End Sub
Problem 1: this code does not work. the new ID is added on the table, but the message box doesn't pop up when I put a new studentID.
Problem 2: although I would like to put each digit of studentID one by one when I put student ID, the first ID number abruptly pops up and if I want other number to put, I need to delete the first studentID. (i.e. if I want to put 0004, it automatically pops up 0001(the first ID) when I put first '0' on the box. then I should delete the '001' and then put '004'.)
Can I put the studentID one by one?
Please forgive my terrible english.

Can anybody help me out?