Error 13 Type Mismatch

  • Thread starter Thread starter Steve Jensen
  • Start date Start date
S

Steve Jensen

I have an ADP, parts of which go back to 1995. Recently I recompiled it
after making minor changes to a form, and after opening the code window and
saving the changes, a function that had previously worked for years stopped
working.

The function loops through fields in a querydef and sets the name and
recordsource of fields on a form to the fields in the querydef. The code is:

Dim i As Integer, rsQBF As ADODB.Recordset, intFieldCount As Integer
Dim frmPreviewForm As Form, fldPreview As Field, intRetval As Integer
Dim mqdf as QueryDef

For i = 0 To intFieldCount - 1
Set fldPreview = mqdf.Fields(i)
frmPreviewForm!SQLResults.Form("label" & (i + 1)).Caption =
fldPreview.Name
frmPreviewForm!SQLResults.Form("txtField" & (i + 1)).ControlSource =
fldPreview.Name
Next

the Set flePreview = mqdf.Fields(i) throws an error 13, which it has never
done before.

In order to correct the problem, I had to rem out this line and change the
next 2 lines as follows:

frmPreviewForm!SQLResults.Form("label" & (i + 1)).Caption =
mqdf.Fields(i).Name
frmPreviewForm!SQLResults.Form("txtField" & (i + 1)).ControlSource =
mqdf.Fields(i).Name

Since nothing other than automatic updates have been installed on my
development computer, I can only assume this is the result of one of them.
Any other ideas?
 
See whether changing the declaration to fldPreview As DAO.Field helps.

The Field object exists in both the ADO and DAO models, but since you're
talking about a field from a QueryDef object (which is only in the DAO
model), you need to ensure you're getting a DAO field, not an ADO one.

Don't know why that should suddenly be a problem, though.
 
Since all you're using is the name of the field, why not change fldPreview
to a string, and use

fldPreview = mqdf.Fields(i).Name
 
I have worked around the problem as I indicated; however, I want to know why
something that has worked for ages suddenly doesn't work any more. The
application has not been changed. The code should work as is.
 
I have run it with Access 2003 but it is maintained and compiled with Access
2000, and the error occurs in both versions. It may still be an Access 2003
service pack issue, though.

The program worked in the compiled ADE state for months (the last compiled
version still does), and was only recompiled recently because of unrelated
program tweaks; therefore it could have been any updates since it was last
compiled in November 2007.
 
Back
Top