Problem with Parameter Form

B

Bill

I created a parameter for to collect three pices of information for a report:
1. Employee name
2. start date
3. end date

I entered the code according to the microsoft access online website
(http://office.microsoft.com/en-us/access/HA011170771033.aspx?pid=CH063653181033)

I can run the report and the dialog box will come up, but the 'OK' and
'cancel' buttons don't work. It's just frozen.

Since I know you will be asking for the VBA coding here it is...I put the
name for each code in CAPS...

FOR THE FORM (OnOpen):
Option Compare Database

Private Sub Cancel_Click()
DoCmd.Close
End Sub

Private Sub Form_Open(Cancel As Integer)
If Not bInReportOpenEvent Then
' If we're not called from the report
MsgBox "For use from the Evals by Employee Name (date range) Report
only", _
vbOKOnly
Cancel = True
End If
Form_Open_Exit:
Exit Sub
End Sub

Private Sub OK_Click()
Me.Visible = False
End Sub


FOR THE REPORT (OnOpen):
Option Compare Database

Private Sub Report_Close()
DoCmd.Close acForm, "Employee Date Range Dialog"
End Sub

Private Sub Report_Open(Cancel As Integer)
' Set public variable to true to indicate that the report
' is in the Open event
bInReportOpenEvent = True

' Open Sales By Category Dialog
DoCmd.OpenForm "Employee Date Range Dialog", , , , , acDialog

' Cancel Report if User Clicked the Cancel Button
If IsLoaded("Employee Date Range Dialog") = False Then Cancel = True

' Set public variable to false to indicate that the
' Open event is completed
bInReportOpenEvent = False
End Sub

FOR THE REPORT (OnClose):
Option Compare Database

Private Sub Report_Close()
DoCmd.Close acForm, "Employee Date Range Dialog"
End Sub

Private Sub Report_Open(Cancel As Integer)
' Set public variable to true to indicate that the report
' is in the Open event
bInReportOpenEvent = True

' Open Sales By Category Dialog
DoCmd.OpenForm "Employee Date Range Dialog", , , , , acDialog

' Cancel Report if User Clicked the Cancel Button
If IsLoaded("Employee Date Range Dialog") = False Then Cancel = True

' Set public variable to false to indicate that the
' Open event is completed
bInReportOpenEvent = False
End Sub

FOR THE MODULE:
Option Compare Database
Option Explicit
Public bInReportOpenEvent As Boolean ' Is report in the Open event?

Function IsLoaded(ByVal strFormName As String) As Boolean
' Returns True if the specified form is open in Form view or
' Datasheet view.
Dim oAccessObject As AccessObject
Set oAccessObject = CurrentProject.AllForms(strFormName)
If oAccessObject.IsLoaded Then
If oAccessObject.CurrentView <> acCurViewDesign Then
IsLoaded = True
End If
End If
End Function


Please let me know if you need any additional information.

Thanks in advance...
 
M

Mark A. Sam

Bill said:
I created a parameter for to collect three pices of information for a
report:
1. Employee name
2. start date
3. end date

I entered the code according to the microsoft access online website
(http://office.microsoft.com/en-us/access/HA011170771033.aspx?pid=CH063653181033)

I can run the report and the dialog box will come up, but the 'OK' and
'cancel' buttons don't work. It's just frozen.

Hello Bill,

Check the Click propeties for the OK and Cancel buttons that they say
EventProcedure. That is all I can think.

God Bless
Mark A. sam
 
B

Bill

OK, I got the buttons to work, but now it runs the quesry, not the report.
What do I need to change in the VBA to make it run the report?
 
M

Mark A. Sam

In the Click event of a button on a form use the OpenForm method of the
DoCmd object:

DoCmd.OpenReport "Report Name", acPreview

According to the article, your parameter for shoud open up with the report.
 
B

Bill

I tried that and it didn't do anything. Maybe I'm changing the wrong line in
the code.

Here's the VBA for my buttons:

Option Compare Database

Private Sub Cancel_Click()
DoCmd.Close 'Close Form
End Sub

Private Sub Form_Open(Cancel As Integer)
If Not bInReportOpenEvent Then
' If we're not called from the report
MsgBox "For use from the Evals by Employee Name (date range) Report
only", _
vbOKOnly
Cancel = True
End If
Form_Open_Exit:
Exit Sub
End Sub

Private Sub OK_Click()
Me.Visible = False
DoCmd.OpenQuery "Evals by Employee Name (date range)", acViewNormal, acEdit
DoCmd.Close acForm, "Employee Date Range Dialog"
End Sub

What am I changing to run the report instead of just the query?

Bill
 

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