Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

From a Form to a Report showing only specified record? 1

Status
Not open for further replies.

Remeartificer

Technical User
May 7, 2004
42
GB
I have a Form showing my records.

I want to scroll through the form and find a specific record and then click a control button that takes me to a report showing only the last record I was looking at.

I have tried the few queries I know but I am failing, can anyone help?

Thanks :)
 


My report gets its data from a query, could this be the problem?

Form: frmForm1
Query: qryCompany
Report: rptForm1

Common field: TaskID

It feels like it should be really simple to solve but this is now doing my head in :( Help!!!!!

.......................................
Suggestion: (This didnt work)

Use the OpenReport's Where condition to specify your record. For example, the following code placed behind a command button on the form would use the RunID control on the form to restrict the Report to only one record.

'******************** Code Start ************************
Dim strDocName As String
Dim strWhere As String
strDocName = "rptSomeReport"
strWhere = "[RunID]=" & me!RunID
DoCmd.OpenReport strDocName, acPreview, , strWhere
'******************** Code End ************************
 
Seems you have to replace RunID with TaskID.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I gave that a go when I played around with the code but it still doesnt bring up the record on the report that I just had on my form?????
 
Here is what I have so far, but it comes up with the following error:

"The action or method requires a report name argument"?

#####################################

Private Sub Command21_Click()
On Error GoTo Err_Command21_Click

Dim stDocName As String

stDocName = "rptForm1"
strWhere = "[TaskID]=" & Me!TaskID
DoCmd.OpenReport strDocName, acPreview, , strWhere

Exit_Command21_Click:
Exit Sub

Err_Command21_Click:
MsgBox Err.Description
Resume Exit_Command21_Click

End Sub

###############################
 
Start using Option Explicit at the top of every routine ;-) which would have found this:

[tt] Dim stDocName As String

stDocName = "rptForm1"
strWhere = "[TaskID]=" & Me!TaskID
DoCmd.OpenReport strDocName, acPreview, , strWhere[/tt]

Roy-Vidar
 
Ouch - Option Explicit at the top of every Module, not routine as I stated.

To make that happen automaticly for all new modules, in VBE - Tools | Options, check "Require Variable Declaration".

Roy-Vidar
 
I think I have now entered the water of the advanced programming :( and I am sinking fast.

I am not too sure how to proceed. I have bought all the books and have finally sussed Entities and relationships etc... and now I am falling at a simple task such as this. Not happy.

How comes I can go from one form to another linking me straight to the record I was just looking at but I cant go from a form to a report?

I could just scroll thru the numerous reports and print out the one I want or do a parameter query but I thought it would be better to do a filter or code to take me direct to the record I want.

If someone has the time, could they guide me thru the process of doing it? It would be sooo appreciated :)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top