User defined datatype?

R

Ray

I have a test file I used to show that a particular technique for generating
letters and incorporating data from a database would work. This called a
routine 'SaveDocs':
Sub SaveDocs()
CreateDocs printmode:=False, savemode:=True
End Sub

Private Sub CreateDocs(printmode As Boolean, savemode As Boolean)
Dim objConn As New Connection
Dim objRS As New Recordset

objConn.ConnectionString = c_DBCon
objConn.Open
objRS.Open c_SQL, objConn
Do While Not objRS.EOF
CreateDoc objRS, printmode, savemode
objRS.MoveNext
Loop
objRS.Close
objConn.Close
End Sub

Where c_DBCon and c_sql are global constants (text) which contain the
database information and SQL query respectively. CreateDoc is another Private
Sub that creates a letter from a singe recordset. This worked, and still
works fine. I am using exactly the same code in another document (with a
different CreateDoc routine) but I now get a compile error stating that 'A
user defined datatype is not defined' in the line:
Dim objConn As New Connection
In neither case have I defined a datatype for objConn (Recordset is also not
recognised as a datatype in the module). Is there another possible reason
this error message could be generated?

Thanks for any suggestions.

Ray
 
J

Jay Freedman

In the document where it doesn't work, you're missing a reference.
Open the VBA editor, go to Tools > References, and put a check next to
"Microsoft ActiveX Data Objects Library" for the highest release
available in the list.

That library (better known as MS ADO) is where the declarations of the
Connection and Recordset types exist; without the reference, VBA
assumes that you're trying to use user-defined types for which you've
failed to give declarations.

If you open the code for the macro where it works and look in Tools >
References, I expect you'll find the library is checked.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 

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