Error 13 was generated by HID - Type Mismatch

  • Thread starter Thread starter Mike Morgan
  • Start date Start date
M

Mike Morgan

We're having a strange problem using Access with a SQL 2000 database. This code used to work. Somehow Access lost the reference to the DAO 3.6 library. At that point it threw an error saying that Workspace was an undefined user defined object. I added DAO 3.6 back and it again recognized the Workspace declaration. But, when it tries to open a connection (see Set HID line below) it throws a "Error 13 was generated by HID - Type Mismatch". I can't figure out why its doing this. This code worked great for the longest time. "HID" is a valid ODBC datasource. OpenConnection requires a string. HID is a connection. OpenConnection returns a connection. What am I missing?

HID is an ODBC datasource.

' From constants section
Const QryExpungeIncidentActivity = "EXECUTE ExpungeACTIVITY "

' Other unrelated subroutines are here

Private Sub btnExpunge_Click()

Dim dbHistorical As Workspace
Dim HID As Connection
Dim ExpungeQry As String
Dim Response As Integer

On Error GoTo ERRORTRAP:

Response = MsgBox("Are you sure you want to expunge this item?", vbQuestion + vbYesNo, "Expungement")

If (Response = vbYes) Then

Set dbHistorical = CreateWorkspace("HistoricalInquiries", "admin", "", dbUseODBC)
Set HID = dbHistorical.OpenConnection("HID") '------------ Throws error: Error 13 was generated by HID - Type Mismatch
ExpungeQry = QryExpungeIncidentActivity & CStr(lstExpungements.Value)
HID.Execute (ExpungeQry)
HID.Close
dbHistorical.Close
Call btnRefresh_Click

End If

Exit Sub

ERRORTRAP:

Call ErrorRoutine
Resume Next

End Sub
 
Do you also have a reference to the ADO (ActiveX Data Objects) library? If
so, my guess is that the DAO reference used to be above the ADO reference in
the list of references, but is now below it. When objects with the same name
exisit in more than one library, and you don't specify which library to use,
VBA will default to using whichever library appears first in the list of
references. Either moving the DAO reference back above the ADO reference, or
'disambiguating' by specifying the library when declaring the variable (Dim
HID As DAO.Connection) should fix it.

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.


We're having a strange problem using Access with a SQL 2000 database. This
code used to work. Somehow Access lost the reference to the DAO 3.6 library.
At that point it threw an error saying that Workspace was an undefined user
defined object. I added DAO 3.6 back and it again recognized the Workspace
declaration. But, when it tries to open a connection (see Set HID line
below) it throws a "Error 13 was generated by HID - Type Mismatch". I can't
figure out why its doing this. This code worked great for the longest time.
"HID" is a valid ODBC datasource. OpenConnection requires a string. HID is a
connection. OpenConnection returns a connection. What am I missing?

HID is an ODBC datasource.

' From constants section
Const QryExpungeIncidentActivity = "EXECUTE ExpungeACTIVITY "

' Other unrelated subroutines are here

Private Sub btnExpunge_Click()

Dim dbHistorical As Workspace
Dim HID As Connection
Dim ExpungeQry As String
Dim Response As Integer

On Error GoTo ERRORTRAP:

Response = MsgBox("Are you sure you want to expunge this item?",
vbQuestion + vbYesNo, "Expungement")

If (Response = vbYes) Then

Set dbHistorical = CreateWorkspace("HistoricalInquiries", "admin",
"", dbUseODBC)
Set HID = dbHistorical.OpenConnection("HID") '------------ Throws
error: Error 13 was generated by HID - Type Mismatch
ExpungeQry = QryExpungeIncidentActivity &
CStr(lstExpungements.Value)
HID.Execute (ExpungeQry)
HID.Close
dbHistorical.Close
Call btnRefresh_Click

End If

Exit Sub

ERRORTRAP:

Call ErrorRoutine
Resume Next

End Sub
 
That was it exactly. I put declaration line in as you suggested and it fixed
the problem. Thank you for your help.
 
In this case, you should take to good habit of writing DAO or ADODB before
the type of your objects; for example:

Dim HID As DAO.Connection

This will remove the possibility of confusion between DAO and ADODB.

S. L.
 
Back
Top