Type Mismatch error with unsure code??

pablavo

Registered User.
Local time
Today, 10:34
Joined
Jun 28, 2007
Messages
189
Hey there
I'm redesigning a database and want to use some of the same code as the previous one. I'm having a problem with part of the code.

The code is to enter a new record; taking fields from the last record within a table "tblProjectMain" (UGA 001) and creating a record to follow on from this automatically - (UGA 002). (The is a Uganda Project by the way)

Once the user accepts this code from a dialog box the code will open another form to add details. In this forms After insert-event there is code which is this:

Private Sub Form_AfterInsert()
Dim db1 As Database
Dim rsYears As Recordset

Set db1 = CurrentDb
Set rsYears = db1.OpenRecordset("TblProjectMain")
rsYears.AddNew
rsYears![CountryPrefix] = Left(Me.FullCode, 3)
rsYears!
Code:
 = Mid(Me.FullCode, 7, 3)
        rsYears![Suffix] = 1
    rsYears.Update
    rsYears.Close
    db1.Close
    
End Sub[/COLOR]

I'm kind of just starting out on VBA and I can only assume this creates a record within another table to add the year of the project which would end up like this (UGA 007/1)  and can have several years, hence, tblProjectYear. but this table isn't within this code.

I'm getting an "type mismatch" error and it's stopping at the part I've coloured blue?  

Does anyone know what might be the problem? I know that a type mismatch would be a datatype mismatch for example but as I'm not sure about the code, perhaps someone could shed some light on this one?

Thanks:confused:
 
Try changing this:
Dim db1 As Database
Dim rsYears As Recordset


to this:

Dim db1 As DAO.Database
Dim rsYears As DAO.Recordset
 
Thanks Bob!

After having looked at three sets of code from the old database I came to the conclusion that this code wasn't supposed to be there and was left by mistake. There's code that does the job. Means that for seven years users have been getting this error for nothing.

I just removed it and worked. I did try the DAO out of curiousitly, but I was just getting an error

No matter... thanks
 

Users who are viewing this thread

Back
Top Bottom