473,402 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Dynamic Choice - Print or Preview

Jon
I'm trying to set an (within options table, tblOptions) a setting that can
be read, whehter all reports should be printed or previewed. I'm happy to
email a sample db if required. When I use the setting I get a Run-time error
'13' Type mismatch!!

I have:

1 table - tblOptions with
1 field - "PrintOrPreview" - a 50 character Text field
1 report - "rptTEST" - just a label on it
1 form - with a button and a combo box to chaing the vaule of
"PrintOrPreview"

The code for the combo box:

Private Sub cmbPrintOrPreview_AfterUpdate()
Call SetPrintChoice
End Sub

Which is:

Function SetPrintChoice()
Dim rst As DAO.Recordset
Dim stSQL As String

stSQL = "SELECT * FROM tblOptions;"
Set rst = CurrentDb.OpenRecordset(stSQL)

If rst.RecordCount > 0 Then 'in case the options record
has gone!
rst.MoveFirst 'in case another
record was added by mistake!
Select Case rst("PrintOrPreview")
Case "ChooseToPreview"
gblPrintOrPreview = "acViewPreview"
Case "ChooseToPrint"
gblPrintOrPreview = "acViewNormal"
Case Else
gblPrintOrPreview = "acViewPreview"
End Select
'let's see what it's showing....
Debug.Print "Print setting: " & gblPrintOrPreview
End If
End Function

And finally the code for the button:

Private Sub cmdPrint_Click()
' DoCmd.OpenReport "rptTEST", acViewNormal
' DoCmd.OpenReport "rptTEST", acViewPreview

'Either of these work, but as soon as I change it to
DoCmd.OpenReport "rptTEST", gblPrintOrPreview
'then I get a "Type mismatch Error"

End Sub

===========================

Surely this has been done before! What am I do wrong? Please help if you
can, thank you

Jon


Nov 13 '05 #1
3 1793

"Jon" <jon@SPAM_OFFtheexperts.co.uk> wrote in message
news:da**********@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com...
I'm trying to set an (within options table, tblOptions) a setting that can
be read, whehter all reports should be printed or previewed. I'm happy to
email a sample db if required. When I use the setting I get a Run-time error '13' Type mismatch!!

I have:

1 table - tblOptions with
1 field - "PrintOrPreview" - a 50 character Text field
1 report - "rptTEST" - just a label on it
1 form - with a button and a combo box to chaing the vaule of
"PrintOrPreview"

The code for the combo box:

Private Sub cmbPrintOrPreview_AfterUpdate()
Call SetPrintChoice
End Sub

Which is:

Function SetPrintChoice()
Dim rst As DAO.Recordset
Dim stSQL As String

stSQL = "SELECT * FROM tblOptions;"
Set rst = CurrentDb.OpenRecordset(stSQL)

If rst.RecordCount > 0 Then 'in case the options record has gone!
rst.MoveFirst 'in case another
record was added by mistake!
Select Case rst("PrintOrPreview")
Case "ChooseToPreview"
gblPrintOrPreview = "acViewPreview"
Case "ChooseToPrint"
gblPrintOrPreview = "acViewNormal"
Case Else
gblPrintOrPreview = "acViewPreview"
End Select
'let's see what it's showing....
Debug.Print "Print setting: " & gblPrintOrPreview
End If
End Function

And finally the code for the button:

Private Sub cmdPrint_Click()
' DoCmd.OpenReport "rptTEST", acViewNormal
' DoCmd.OpenReport "rptTEST", acViewPreview

'Either of these work, but as soon as I change it to
DoCmd.OpenReport "rptTEST", gblPrintOrPreview
'then I get a "Type mismatch Error"

End Sub

===========================

Surely this has been done before! What am I do wrong? Please help if you
can, thank you

Jon


I can see why this is confusing. The second argument for DoCmd.OpenReport
needs to be numeric. Go to the debug screen and try this:

?acviewnormal
0
?acviewpreview
2

Notice that those constants are numeric. You are setting gblPrintOrPreview
to a string value. You need to, either use a select/case statement and then
the appropriate constant, or set gblPrintOrPreview to a numeric value to
begin with.

HTH,
Randy

Nov 13 '05 #2
You use string literals where you should use constants.

Jon wrote:
gblPrintOrPreview = "acViewPreview"


must become
gblPrintOrPreview = acviewpreview

You don't need to use a global variable if you convert the
SetPrintChoice sub to a GetPrintChoice function, assigning the value
found in the table to the function result, and calling that in the
OpenReport method. But that is a different issue.

--
Bas Cost Budde, Holland
http://www.heuveltop.nl/BasCB/msac_index.html
For human replies, replace the queue with a tea

Nov 13 '05 #3
Jon

Bas Cost Budde Wrote:
You use string literals where you should use constants.
Jon wrote: gblPrintOrPreview = "acViewPreview"


must become
gblPrintOrPreview = acviewpreview

You don't need to use a global variable if you convert the
SetPrintChoice sub to a GetPrintChoice function, assigning the value
found in the table to the function result, and calling that in the
OpenReport method. But that is a different issue.

--
Bas Cost Budde, Holland
http://www.heuveltop.nl/BasCB/msac_index.html
For human replies, replace the queue with a tea

Bas and Randy, thank you. It's a sub in my test DB, was a function before!

I now understand where I was going wrong and will sort this - thank you.

Jon
Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Pat | last post by:
I would like to send the Print Preview of a MS Access form to a Snapshot file. The form contains an OLE graph. BACKGROUND A snapshot of a report is possible. If I could I would use a report to...
1
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
0
by: CSDunn | last post by:
Hello, I have a format issue on an Access 2000 ADP report that I am going to attempt to explain from a 'ten thousand foot view' : I have an Access 2000 ADP report that has a SQL Server 2000...
0
by: John | last post by:
I have a class that creates an AxWebBrowser object in the background, loads some arbitrary html content, then shows the user a print preview. The only problem is, this print preview is a tiny...
2
by: Dean Slindee | last post by:
Anybody written code in VB.NET to: 1) show a print preview window of reports already written and stored in an Access 2002 database; or 2) execute the print of a report stored in an Access 2002...
2
by: deejayquai | last post by:
Hi I'm trying to produce a report based on a dynamic crosstab. Ultimately i'd like the report to actually become a sub report within a student end of year record of achievement. The dynamic...
6
by: CSharpguy | last post by:
In my gridview I have 2 -3 template fields which are hyperlinks. I allow the user to print this grid. When the grid prints it also prints the links, how can I take the user to a print preview page...
9
by: igotyourdotnet | last post by:
I need to create a print preview page BUT my page I need to print has a grid and in the grid I have 2 or 3 columns that have links I want to hide the columns with the links on my print preview page...
11
by: Gord | last post by:
When I open a certain report, it runs some code that generates the records that will be displayed in that report. This works fine. When I go to print preview the report it appears that the code...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.