I have a 2007 Access database that is split on a network to allow multiple users to enter data at the same time. (I just used the wizard yesterday so don't assume I am an expert). This database was created in Access 2003 by someone else and I converted it to 2007. There is a form to "Add a new Employee" that once the data is filled in the form and the button is pressed it should populate a table in the backend database. The problem is that when you press the button I get "type mismatch" error. Here is the code behind the button. Let me know what you think the problem is. There are also other forms that work on this same principle and they all have problems too.
Thanks for the help.
Private Sub add_Click()
On Error GoTo add_Click
Dim db As Database
Dim rs As Recordset
Dim Directorate, Department, Last_Name, Employee_Type, Career_Path, First_Name As String
Set db = CurrentDb()
'this opens up the database the form is in. Leave as is.
Set rs = db.OpenRecordset("Employee Name")
'and this opens up the recordset you want to add the records to. It is the name of the table in "s
Directorate = Me.Combo15
Department = Me.Combo5
Last_Name = Me.Text2
Employee_Type = Me.Combo7
Career_Path = Me.Combo9
First_Name = Me.Text0
'....... do this for all the controls. This loads the values of the fields into the variables.
With rs
'This implies that there is rs before each . or !
.AddNew
!Directorate = Directorate
!Department = Department
!Last_Name = Last_Name
!Employee_Type = Employee_Type
!Career_Path = Career_Path
!First_Name = First_Name
.Update
.Close
End With
MsgBox "This Employee has been saved.", vbOKOnly
'DoCmd.Close acForm, "New_Employee", acSaveNo
add_Click:
'MsgBox "This Employee already exits in database", vbOKOnly
Set db = Nothing
Set rs = Nothing
'These close the recordset
End Sub
Thanks for the help.
Private Sub add_Click()
On Error GoTo add_Click
Dim db As Database
Dim rs As Recordset
Dim Directorate, Department, Last_Name, Employee_Type, Career_Path, First_Name As String
Set db = CurrentDb()
'this opens up the database the form is in. Leave as is.
Set rs = db.OpenRecordset("Employee Name")
'and this opens up the recordset you want to add the records to. It is the name of the table in "s
Directorate = Me.Combo15
Department = Me.Combo5
Last_Name = Me.Text2
Employee_Type = Me.Combo7
Career_Path = Me.Combo9
First_Name = Me.Text0
'....... do this for all the controls. This loads the values of the fields into the variables.
With rs
'This implies that there is rs before each . or !
.AddNew
!Directorate = Directorate
!Department = Department
!Last_Name = Last_Name
!Employee_Type = Employee_Type
!Career_Path = Career_Path
!First_Name = First_Name
.Update
.Close
End With
MsgBox "This Employee has been saved.", vbOKOnly
'DoCmd.Close acForm, "New_Employee", acSaveNo
add_Click:
'MsgBox "This Employee already exits in database", vbOKOnly
Set db = Nothing
Set rs = Nothing
'These close the recordset
End Sub