print code error

A

after.effect.27

I dont have much experience with visual basic or Microsoft Access, so
heres my problem.

I am converting old databases from access 97 ot 2003, and I have
successfully done it. Now, I'm going through each form to see if it
works the same way it used to. Everything was good until I came across
a print function.
I get this error:


Compile Error: User-Defined type not defined.


It then leads me to this section of code:


Function PrintVoucher(Sarg As String)
Dim db As Databased, ds As Dynaset
If Sarg = "S" Then
Set db = CurrentDb()
Set ds = db.CreateDynaset("vouchquery")
msg = "Please enter voucher number to print"
title = "Voucher Request"
answer = InputBox$(msg, title)
If Len(answer) = 0 Then
Exit Function


The printer is an Epson FX 880 Dot Matrix, and thats not the problem to

my knowledge. If anyone has any clue on how I can get this to print,
please fill me in.


Here are screenshots of what I am doing:
This is where i press the print button.
http://i4.photobucket.com/albums/y102/xmav27x/error1.jpg


This is what comes up.
http://i4.photobucket.com/albums/y102/xmav27x/error2.jpg


Thanks.
 
D

Dirk Goldgar

I dont have much experience with visual basic or Microsoft Access, so
heres my problem.

I am converting old databases from access 97 ot 2003, and I have
successfully done it. Now, I'm going through each form to see if it
works the same way it used to. Everything was good until I came across
a print function.
I get this error:


Compile Error: User-Defined type not defined.


It then leads me to this section of code:


Function PrintVoucher(Sarg As String)
Dim db As Databased, ds As Dynaset
If Sarg = "S" Then
Set db = CurrentDb()
Set ds = db.CreateDynaset("vouchquery")
msg = "Please enter voucher number to print"
title = "Voucher Request"
answer = InputBox$(msg, title)
If Len(answer) = 0 Then
Exit Function


The printer is an Epson FX 880 Dot Matrix, and thats not the problem
to

my knowledge. If anyone has any clue on how I can get this to print,
please fill me in.


Here are screenshots of what I am doing:
This is where i press the print button.
http://i4.photobucket.com/albums/y102/xmav27x/error1.jpg


This is what comes up.
http://i4.photobucket.com/albums/y102/xmav27x/error2.jpg


Thanks.

Did you rewrite any of that code? I've never heard of a "Databased"
type, even in the DAO 2.5/3.5 compatibility library. "CreateDynaset"
would have to be a very old type, maybe used in Access 2.0, but not
supported even in Access 97's DAO 3.5.

In Access 2003, using DAO 3.6, you would have use code along the lines
of this:

Dim db As DAO.Database, ds As DAO.Recordset
If Sarg = "S" Then
Set db = CurrentDb()
Set ds = db.OpenRecordset("vouchquery", dbOpenDynaset)

' ...

I can't see all the rest of the code, so I can't see what other changes
might be required.
 
D

Dirk Goldgar

http://groups.google.com/group/Access-VBA/browse_thread/thread/2d5908822207b51e

there is a topic with the full code. thanks for the help so far.

I think the definition "As Databased" is just plain in error, and should
be "As Database". If you fix that, the code would compile if you used
the DAO 2.5/3.5 Compatibility Library instead of DAO 3.6. However, you
should not use that library. Instead you should use the DAO 3.6
library, which I believe Access 2003 references by default, and make the
following changes, wherever the "change from" text occurs:

Change from: As Databased
to: As DAO.Database

Change from: As Database
to: As DAO.Database

Change from: As Dynaset
to: As DAO.Recordset

Change from: CreateDynaset(<whatever>)
to: OpenRecordset(<whatever>, dbOpenDynaset)

Change from: A_PRINT
to: acViewNormal

Change from: A_REPORT
to: acReport

If you make those changes, I think the code will compile and will
probably work. I don't think you need to be closing reports after
opening them to print, as is being done in these lines ...

DoCmd.OpenReport "vouchrep", A_PRINT, , repstring
DoCmd.Close A_REPORT, "vouchrep"

and similar, but I doubt it does any harm. You can probably delete that
DoCmd.Close line, though.
 
A

after.effect.27

Ok, that seemed to get rid of that issue. Now, I press the function and
I get Run-Time Error '3078': The Microsoft Jet database engine cannot
find the input table or query 'vouchquery, dbOpenDynaset'. Make sure it
exists and is spelled correctly.

I have a query name vouchquery.
 
D

Dirk Goldgar

Ok, that seemed to get rid of that issue. Now, I press the function
and I get Run-Time Error '3078': The Microsoft Jet database engine
cannot find the input table or query 'vouchquery, dbOpenDynaset'.
Make sure it exists and is spelled correctly.

I have a query name vouchquery.

I can't say for sure, but I suspect you wrote this:

OpenRecordset("vouchquery, dbOpenDynaset")

when you should have written this:

OpenRecordset("vouchquery", dbOpenDynaset)
 

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