Hey guys,
Im trying to build a new database project from scartch and I have copied exactly my code from a similar project (I think.) I cannot find out why the type mismatch error 13 gets thrown at me when I fill out the form and try and add the record.
If anyone has any idea, I'd be grateful.
P.S. The Vba debugger points to the line with:
Set tblCase = New ADODB.Recordset
-Thanks,
Z
Im trying to build a new database project from scartch and I have copied exactly my code from a similar project (I think.) I cannot find out why the type mismatch error 13 gets thrown at me when I fill out the form and try and add the record.
Code:
Private Sub cmdAddNew_Click()
Dim err As Integer
Dim cnn1 As ADODB.Connection
Dim tblCase As ADODB.Recordset
Dim StrCnn As String
'***************************************************
'Check that all fields have been completed correctly
'***************************************************
txtName.SetFocus
If txtName.Text = "" Then
err = err + 1
MsgBox "Please enter the name of the subject" & err
End If
cboInfection.SetFocus
If cboInfection.Text = "" Then
err = err + 1
MsgBox "Please specify infection type." & err
End If
cboPrecaution.SetFocus
If cboPrecaution.Text = "" Then
err = err + 1
MsgBox "Please specify type of precaution." & err
End If
cboUnit.SetFocus
If cboUnit.Text = "" Then
err = err + 1
MsgBox "Please specify unit." & err
End If
txtRoom.SetFocus
If txtRoom.Text = "" Then
err = err + 1
MsgBox "Please specify room number." & err
End If
txtStartDate.SetFocus
If txtStartDate.Text = "" Then
err = err + 1
MsgBox "Please indicate the date when isolation precautions began."
End If
txtEndDate.SetFocus
If txtEndDate.Text = "" Then
err = err + 1
MsgBox "Please indicate date when isolation precautions terminated, or subject was discharged, or deceased."
End If
'If no errors, insert data into table
If err < 1 Then
'Open a connection
Set cnn1 = New ADODB.Recordset
mydb = "G:\Medical\LaboratoryMedicine\InfectionControl\Statistics\Fiscal 2009\DB Conversion (Matt)\Infection Control Stats.mdb"
StrCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mydb
cnn1.Open StrCnn
'Open Case Table (tblCase)
Set tblCase = New ADODB.Recordset
tblCase.CursorType = adOpenKeyset
tblCase.LockType = adLockOptimistic
tblCase.Open "tblCase", cnn1, , , adCmdTable
'Get the new record data
tblCase.AddNew
tblCase![Subject's Name] = txtName
tblCase![Infection Type] = cboInfection
tblCase![New Case?] = opNew
tblCase![Isolation Precautions] = cboPrecaution
tblCase![Unit] = cboUnit
tblCase![Room Number] = txtRoom
tblCase![Isolation Start Date] = txtStartDate
tblCase![Isolation End Date] = txtEndDate
tblCase![Notes] = txtNotes
tblCase![K#] = txtKNumber
'Show the newly added record for confirmation
MsgBox "Case for: " & tblCase!txtName & " Has been successfully added to database."
'Close connections to DB.
tblCase.Close
cnn1.Close
'Clear all objects
Me.txtName = ""
Me.cboInfection = ""
Me.cboPrecaution = ""
Me.opNew = ""
Me.cboUnit = ""
Me.txtRoom = ""
Me.txtStartDate = ""
Me.txtEndDate = ""
Me.txtNotes = ""
Me.txtKNumber = ""
'Send back to main page
Else
MsgBox "An error has occured, please verify that all fields are complete and try again. Call Matt (x2244) for further assistance."
End If
End Sub
If anyone has any idea, I'd be grateful.
P.S. The Vba debugger points to the line with:
Set tblCase = New ADODB.Recordset
-Thanks,
Z