Parameters requested twice when opening report

  • Thread starter Thread starter JaneP
  • Start date Start date
J

JaneP

Hi,

I've created a form [Select Name] which ask for a name to be select from a
combo box to run the query [Overdue & Due Actions] which then in turns runs
the report but when it runs the query, which I see has run correctly, it then
asks for the name again but this time I need to type it in. If I don't enter
anything in the 2nd time the report is blank.
The parameters form has an 'OK' button with the following coding for On Click
Private Sub Cancel_Click()
DoCmd.Close 'Close Form
End Sub
Private Sub OK_Click()
Me.Visible = False
DoCmd.OpenQuery "Overdue & Due Actions", acViewNormal, acEdit
DoCmd.Close acForm, "Select Name"
End Sub

The query refers to [Forms]![Select Name]![Name] under the Responsibility
field & if I take this out the report doesn't run properly.

The report's coding is
Private Sub Report_Close()
DoCmd.Close acForm, "Select Name"
DoCmd.Close acQuery, "Overdue & Due Actions"
End Sub

Private Sub Report_Open(Cancel As Integer)
DoCmd.OpenForm "Select Name", , , , , acDialog
End Sub

I've looked at the other questions in the forum & can't seem to find an
answer that works for me. I'm not VBA person so I'm picking up the coding
from different help sources in Microsoft in particular "Using parameters with
queries & reports" but I am now struggling

Thanks
 
JaneP said:
I've created a form [Select Name] which ask for a name to be select from a
combo box to run the query [Overdue & Due Actions] which then in turns runs
the report but when it runs the query, which I see has run correctly, it then
asks for the name again but this time I need to type it in. If I don't enter
anything in the 2nd time the report is blank.
The parameters form has an 'OK' button with the following coding for On Click
Private Sub Cancel_Click()
DoCmd.Close 'Close Form
End Sub
Private Sub OK_Click()
Me.Visible = False
DoCmd.OpenQuery "Overdue & Due Actions", acViewNormal, acEdit
DoCmd.Close acForm, "Select Name"
End Sub

The query refers to [Forms]![Select Name]![Name] under the Responsibility
field & if I take this out the report doesn't run properly.

The report's coding is
Private Sub Report_Close()
DoCmd.Close acForm, "Select Name"
DoCmd.Close acQuery, "Overdue & Due Actions"
End Sub

Private Sub Report_Open(Cancel As Integer)
DoCmd.OpenForm "Select Name", , , , , acDialog
End Sub


While I would open the form in normal mode before opening
the report, I think you code your code will work if you
remove the Close line in the OK event.
 
Thanks, Marshall it worked. I've been going round the bend with this so this
has made my day!

Marshall Barton said:
JaneP said:
I've created a form [Select Name] which ask for a name to be select from a
combo box to run the query [Overdue & Due Actions] which then in turns runs
the report but when it runs the query, which I see has run correctly, it then
asks for the name again but this time I need to type it in. If I don't enter
anything in the 2nd time the report is blank.
The parameters form has an 'OK' button with the following coding for On Click
Private Sub Cancel_Click()
DoCmd.Close 'Close Form
End Sub
Private Sub OK_Click()
Me.Visible = False
DoCmd.OpenQuery "Overdue & Due Actions", acViewNormal, acEdit
DoCmd.Close acForm, "Select Name"
End Sub

The query refers to [Forms]![Select Name]![Name] under the Responsibility
field & if I take this out the report doesn't run properly.

The report's coding is
Private Sub Report_Close()
DoCmd.Close acForm, "Select Name"
DoCmd.Close acQuery, "Overdue & Due Actions"
End Sub

Private Sub Report_Open(Cancel As Integer)
DoCmd.OpenForm "Select Name", , , , , acDialog
End Sub


While I would open the form in normal mode before opening
the report, I think you code your code will work if you
remove the Close line in the OK event.
 
Back
Top