Opening report to pg based on form (1 Viewer)

Cicak

Registered User.
Local time
Today, 12:10
Joined
May 20, 2008
Messages
31
A bit of background: I'm relatively new to Access and with regards to code I know only how to follow directions. I'm using the 2003 version of Access.

Hi,

I've seen something like this in a sample database, but I don't know how they do it:

Once the user is done filling up the form, a button can be clicked, which causes a report to appear. The report presents the data from that record in the form, on one page, and doesn't show the other records.

I have been trying to create this effect. In my case, there is a form (called Mainform), into which users type information about purchase orders (POs). I also have a report (POReport), where each individual page shows information for one PO. On Mainform, a button should open the report according to the PO number of the record being viewed. PO number is a field present on both Mainform and POReport. The button has an "Open Report" macro under the "on click" event.

What can be done to cause the 'correct' page of the report to open? I tried putting "[POTable].[PONumber]" under the criteria argument of the Open Report macro (POTable acts as the source of the form Mainform). But when I click the button I am prompted for something about the PO number. Then when this is entered, the entire report is shown, not just the relevant page.. :(

Sorry if this post is in the wrong place and if it isn't very clear.

Any hints/help is much appreciated..
Thanks in advance!
 

boblarson

Smeghead
Local time
Today, 12:10
Joined
Jan 12, 2001
Messages
32,059
Just call the report like this:

DoCmd.OpenReport "YourReportName", acViewPreview,,"[PONumber]=" & Me!PONumber
 

Cicak

Registered User.
Local time
Today, 12:10
Joined
May 20, 2008
Messages
31
When I tried it I got:
Run-time error "3464"
Data type mismatch in criteria expression

When I click 'debug', the line is highlighted in yellow. If I add brackets so that it looks like 'DoCmd.OpenReport("POReport", acViewPreview, , "[PONumber] = " & Me!PONumber)' then the words are turned red.

I also tried this, which I got from the sample database:

Private Sub PrintPreviewMainform_Click()
On Error GoTo Err_PrintPreviewMainform_Click
If IsNull(Me![PONumber]) Then
MsgBox "Please enter PO information before previewing."
Else
DoCmd.OpenReport "POReport", acViewPreview, , "[PONumber]=" & Me!PONumber
End If
Exit_PrintPreviewMainform_Click:
Exit Sub
Err_PrintPreviewMainform_Click:
MsgBox Err.Description
Resume Exit_PrintPreviewMainform_Click
End Sub

With the code immediately above, when I click the button, a message appears with "Data type mismatch in criteria expression".

Thanks in advance!
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 12:10
Joined
Aug 30, 2003
Messages
36,137
If it's text

DoCmd.OpenReport "POReport", acViewPreview, , "[PONumber]='" & Me!PONumber & "'"
 

Cicak

Registered User.
Local time
Today, 12:10
Joined
May 20, 2008
Messages
31
Thanks! It opens right, only before it opens a message appears with

Enter Parameter Value
POTable
(POTable is the source for the Mainform, and within the Mainform is a subform based on a different table)

If I click 'OK' it opens as I hoped it would. If I click 'Cancel', the information in the subform does not appear and the subform is blank although the fields in the Mainform are fine..
 

Cicak

Registered User.
Local time
Today, 12:10
Joined
May 20, 2008
Messages
31
You can put a command button on the form and have this as the code behind the On Click Event:

Docmd.OpenReport "YourReportName",,,"[RecordId] = forms!YourFormName!RecordID"

I tried this, from a quite-old post in the forms forum, and the same message popped up. Have I linked something wrongly?
 

Cicak

Registered User.
Local time
Today, 12:10
Joined
May 20, 2008
Messages
31
Doing documentation, which I found out about from http://support.microsoft.com/kb/303134, passed me a long list. From what I have read, "Enter Parameter Value" shows up when there has been a typo somewhere or when Access cannot find something (please correct me if I'm mistaken). But the table "POTable" is still there, and is the table behind quite a lot of the information that appears when the report opens (after clicking "OK").

Things work great apart from this "Enter Parameter Value" message and I'm quite puzzled over it. Would really appreciate any pointers..

Thanks!
Regards.
 

Cicak

Registered User.
Local time
Today, 12:10
Joined
May 20, 2008
Messages
31
Thank you

Oh goodness. Strange but true: as I was deleting parts of a back-up database I made for the purposes of posting here, something happened, and as a result the report now opens as it should. The "Enter Parameter Value" doesn't pop up now. Then I tried it again in the actual database and it seems to be one/a few of the text boxes I'd put in for calculations, though I'm not really sure. The expression(s) involved numbers from the POTable. I'll relook these..

Thanks so much! :)
 

Users who are viewing this thread

Top Bottom