Writing fields to a table

AlexB

Registered User.
Local time
Today, 22:20
Joined
Mar 3, 2003
Messages
21
Hi there, Im just knocking up a quick Access thing for work - moving data from a field in a form to a table.


Anybody got any ideas why I get this error? "Runtime error (13) - type mismatch"

We're using Windows 2000 and Access 2002...

Cheers



Option Compare Database

Option Explicit

Private Sub cmdSubmitProject_Click()

Dim rst As Recordset
Set rst = CurrentDb.OpenRecordset("select * from tblProjects")

Dim strMessage As String
Dim intOptions As Integer
Dim bytChoice As Byte
Dim Cancel As Integer

strMessage = "Are you sure you wish to reserve this booking?"
intOptions = vbQuestion + vbOKCancel
bytChoice = MsgBox(strMessage, intOptions)


If lblUserID = "" Then
MsgBox ("You must enter a UserID against the project to continue")
If lblProjectName = "" Then
MsgBox ("You must enter a Project title to continue")
If lblDateStarted = "" Then
MsgBox ("You must enter a Project Start date to continue")
If lblProjectDescription = "" Then
MsgBox ("You must enter a Project Description to continue")

Else
rst.AddNew
rst!UserID = lblUserID
rst!ProjectName = lblProjectName
rst!DateStarted = lblDateStarted
rst!ProjectDescription = lblProjectDescription
rst.Update
rst.Close
MsgBox ("Project added to system.")
DoCmd.Close

End If
End If
End If
End If



' If bytChoice = vbOK Then
' DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
'
' If bytChoice = vbCancel Then
' FirstName.SetFocus ' Go back to Name field.
' Cancel = True ' Cancel saving the record.
' Else

Exit_SaveRecord_Click:
Exit Sub

Err_SaveRecord_Click:
MsgBox Err.Description
Resume Exit_SaveRecord_Click




End Sub
 
If it's a type mismatch then you must be trying to put a data type of one sort into a field that isn't specified to accept that type such as putting a string into a date field, etc.

On which line does your code give this error?
 
It gives me an error on the SET RST bit...

Set rst = CurrentDb.OpenRecordset("select * from tblProjects")

I haven't done VB for a couple of years now and cant really remember what Im doing!
 
Put a semi-colon at the end of your SQL:

("SELECT * FROM tblProjects;")
 
Hmm that still doesnt work

If I right-click on the CurrentDB text and go to definition, the CurrentDB object comes up in the definition window. However, if I then click on the Database link in the example, it says :


"Cannot jump to Database because it is in the library 'DAO' which is not currently referenced".

What gives?
 
In the module, Goto Tools -> References and ensure that Microsoft DAO Object Library 3.5 is checked - and give this a higher priority than Microsoft ActiveX Data Object Library.
 

Users who are viewing this thread

Back
Top Bottom