View Full Version : How to get QBF selected data into Report format?


WebFaktor
02-21-2002, 07:33 AM
The code below allows me to Query By Form, i.e., I can make an information selection via a combo box in my QBF form, press command button (activating code seen below) and the results appear in the QBF's parent form.

Can this type of data retrieval be established for Reports? Or, can I alter code to have results of selection made in QBF form appear, Not in its parent form, but within a report?

Thanks in advance - Michael


Function glrQBF_DoHide(frm As Form)
Dim varSQL As Variant
Dim strParentForm As String

'Get the name of the Parent form
strParentForm = Left(CStr(frm.Name), Len(CStr(frm.Name)) - 4)
'Create the approprite Where clause based on the fields with data in them
varSQL = glrDoQBF(CStr(frm.Name), False)

'Open the Parent form filtered with the Where clause genereated above
DoCmd.OpenForm strParentForm, acNormal, , varSQL
'Make this *_QBF form invisible
frm.Visible = False

End Function

KKilfoil
02-21-2002, 07:44 AM
hth: http://www.access-programmers.co.uk/ubb/Forum1/HTML/005480.html

I can give you more details, if you need them.

WebFaktor
02-21-2002, 10:36 AM
KKilfoil - Thankyou, that reference has me on the right track.

Although, what I'm still struggling with is how to convert my QBF form and parent form situation to this new QBF form and Report circumstance. If I understand correctly, there is No need of a parent form in this QBF form and Report circumstance?

While the code and advice you sent helped me to launch the report from my form, I'm still not clear on how to filter, or control the information appearing in the report?

Any further advice would be greatly appreciated!

Michael

KKilfoil
02-21-2002, 12:40 PM
Ensure your form and report use the same recordsource. I always construct a query and use that as the source for both to be guaranteed a match.

Let the users use whatever methodology they want ot filter (i.e. filter by selection, QBF, filter excluding selection, etc.

I add a text control, [txtFilter] on my form, and set the On Apply Filter event of my FORM to the following code:

Private Sub Form_ApplyFilter(Cancel As Integer, ApplyType As Integer)


Me!TxtFilter.Caption = "Current Filter: " & Me.Filter

End Sub


This populates the txtFilter control with the current filter definition whenever the user applies a filter (or refilter, etc).

Now you want to open a report based on the present (filtered) data on the form. Create a command button and put this code in the On Click event for the button. This previews the report, and the user can click on Print from the preview report toolbar. If you want to print rather than preview, delete the AcPreview value from the DoCmd line (keep the comma!):


Private Sub PreviewMeterReport_Click()
On Error GoTo Err_PreviewMeterReport_Click

Dim stDocName As String

stDocName = "Meter Report"
If Me.FilterOn Then
DoCmd.OpenReport stDocName, acPreview, , Me.Filter
Else
DoCmd.OpenReport stDocName, acPreview
End If

Exit_PreviewMeterReport_Click:
Exit Sub

Err_PreviewMeterReport_Click:
MsgBox Err.Description
Resume Exit_PreviewMeterReport_Click

End Sub


In my specific case, my report was called 'Meter Report', but use whatever you picked.

This should accomplish what you want.

Now you can also print the filter on the report, as per the link in my prior post.

WebFaktor
02-21-2002, 12:52 PM
Thank you for your kind help.

All the best,

Michael