Runtime Error 13

R

Robin Chapple

I am still a beginner using Access 2002 SP3.

I am attempting to format my own field on a form with record number
displayed. I have an unbound field [RecNum] with the code below copied
from one of my older applications.

I get "Runtime error 13 - Type mismatch" at the line marked with
asterisks. Google has not found an example that helps.

Private Sub Form_Current()
Dim rst As Recordset, intCurRec As Integer, _
intTotalRec As Integer

*** Set rst = Me.RecordsetClone***

rst.MoveLast

intCurRec = Me.CurrentRecord

If NewRecord = True Then
intTotalRec = rst.RecordCount + 1
Else
intTotalRec = rst.RecordCount
End If

Me![RecNum] = "Record " & intCurRec & " of " & intTotalRec

End Sub

Thanks,

Robin Chapple
 
M

Mike Revis

Not sure if this is your problem but I seem to remember a similar problem on
an access97 db when I got access2002.

You might try
Dim rst as DAO.Recordset
or
Dim rst as ADO.Recordset

Not sure what the difference is but I think it has to do with version
differences.

Mike
 
V

Van T. Dinh

It looks like you declaration of the Recordset rs defaulted to ADO Recordset
while you need DAO Recordset for a Form's Recordset (in an MDB file).

Make sure you have DAO 3.6 Library in the References and use the declaration
/ Dim statement:

Dim rs As DAO.Recordset
Dim intCurRec As Integer
Dim intTotalRec As Integer
...
 
R

robinski

Thanks Mike,

You pointed me in the right direction. I needed to change references.

Well done.

Robin

Not sure if this is your problem but I seem to remember a similar problem on
an access97 db when I got access2002.

You might try
Dim rst as DAO.Recordset
or
Dim rst as ADO.Recordset

Not sure what the difference is but I think it has to do with version
differences.

Mike

Robin Chapple said:
I am still a beginner using Access 2002 SP3.

I am attempting to format my own field on a form with record number
displayed. I have an unbound field [RecNum] with the code below copied
from one of my older applications.

I get "Runtime error 13 - Type mismatch" at the line marked with
asterisks. Google has not found an example that helps.

Private Sub Form_Current()
Dim rst As Recordset, intCurRec As Integer, _
intTotalRec As Integer

*** Set rst = Me.RecordsetClone***

rst.MoveLast

intCurRec = Me.CurrentRecord

If NewRecord = True Then
intTotalRec = rst.RecordCount + 1
Else
intTotalRec = rst.RecordCount
End If

Me![RecNum] = "Record " & intCurRec & " of " & intTotalRec

End Sub

Thanks,

Robin Chapple
 
R

robinski

Thanks,

DAO 3.6 Library is now selected. It wasn't originally.

This is what I have:

Private Sub Form_Current()

Dim rst As DAO.Recordset, intCurRec As Integer, _
intTotalRec As Integer

Set rst = Me.RecordsetClone

rst.MoveLast

intCurRec = Me.CurrentRecord

If NewRecord = True Then
intTotalRec = rst.RecordCount + 1
Else
intTotalRec = rst.RecordCount
End If

Me![RecNum] = "Record " & intCurRec & " of " & intTotalRec

End Sub

Do I understand properlu that the statements can follow one 'dim" or
should I show them separately?

Robin Chapple
 
D

Douglas J. Steele

Dim rst As DAO.Recordset, intCurRec As Integer, _
intTotalRec As Integer


Do I understand properlu that the statements can follow one 'dim" or
should I show them separately?

What you have is fine. The problem many people have is that they put
something like

Dim intCurRec, intTotalRec As Integer

thinking that declares both variables to be integers. It doesn't: in that
case, only intTotalRec is declared as an Integer, while intCurRec will be a
variant.
 
V

Van T. Dinh

What you used is fine as per Douglas' advice.

OTOH, I tend to dim each one separately since I can just delete the whole
statement or temporarily comment out each variable independently.
Occosionally, I may need to change the variable to Static rather than Dim,
also. I find it is easier to read with each variable declared on a separate
line.

Note also that most Microsoft sample codes also use separate Dim statements
for variables.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top