Opening a report through a form.

J

James

I have a form that has one combo box with all of the employee's in it, and
later will add a date range. When I select the employee from the list and
then hit the view report button nothing is diplayed and no error messages.
If I don't have an employee in it it shows the error message to select the
employee like I want. The code is below for both the form and the report.

This is from the Form:

Private Sub btnDriver_Click()
If IsNull([cmbDriver]) Then
MsgBox "You must select a driver's name from the list."
DoCmd.GoToControl "cmbDriver"
Else
Me.Visible = False
End If
End Sub


This is from the report:

Private Sub Report_NoData(Cancel As Integer)
MsgBox "There is no data for this report. Canceling report..."
Cancel = -1
End Sub

Private Sub Report_Close()
DoCmd.Close acForm, "frmDriver"
End Sub

Private Sub Report_Open(Cancel As Integer)
DoCmd.OpenForm "frmDriver", , , , , acDialog, "Driver"
If Not IsLoaded("Driver") Then
Cancel = True
End If
End Sub
 
G

Gurtz

Hi,

It looks like, when the user has selected an employee,
your button just sets the visible property to false. So
where are you trying to open the report?

Gurtz
[email = no $]
 
F

Fredg

James.
Your problem is in the Report's Open event.
Private Sub Report_Open(Cancel As Integer)
DoCmd.OpenForm "frmDriver", , , , , acDialog, "Driver"
If Not IsLoaded("Driver") Then
Cancel = True
End If
End Sub

You open the form, named 'FrmDriver', but you then check to see if the form
named "Driver" is loaded. It isn't loaded because you opened "frmDriver", so
the whole report is cancelled.
Simply correct the name to

If Not IsLoaded("frmDriver") Then

and your report should run (assuming nothing else is going on here).

Also, why are you passing "Driver" as an OpenArgs to the "frmDriver"?

--
Fred

Please reply only to this newsgroup.
I do not reply to personal e-mail.


James said:
I have a form that has one combo box with all of the employee's in it, and
later will add a date range. When I select the employee from the list and
then hit the view report button nothing is diplayed and no error messages.
If I don't have an employee in it it shows the error message to select the
employee like I want. The code is below for both the form and the report.

This is from the Form:

Private Sub btnDriver_Click()
If IsNull([cmbDriver]) Then
MsgBox "You must select a driver's name from the list."
DoCmd.GoToControl "cmbDriver"
Else
Me.Visible = False
End If
End Sub


This is from the report:

Private Sub Report_NoData(Cancel As Integer)
MsgBox "There is no data for this report. Canceling report..."
Cancel = -1
End Sub

Private Sub Report_Close()
DoCmd.Close acForm, "frmDriver"
End Sub

Private Sub Report_Open(Cancel As Integer)
DoCmd.OpenForm "frmDriver", , , , , acDialog, "Driver"
If Not IsLoaded("Driver") Then
Cancel = True
End If
End Sub
 
A

Andy Cole

James

You're opening the Report and then opening the frmDriver in dialog mode. In
frmDriver, you select a Driver and then hide frmDriver. I don't see any
specific code to use the selected driver in your report. Have you set a
reference to Forms!frmDriver!cmbDriver in your report's recordsource
somewhere else?

Andy
 
J

James

I change the "driver" to "frmdriver" and that worked. However, when I open
the query for the report all of the dates are there and the employee that I
entered is there aswell. Thats what is should be. When I open the report
all of the dates are there except the dates that match for the selected
empoloyee. Any reason for this?

I don't know what you are talking about when you say reference in the
reports recordsource. I have in the query under EmplpoyeeId: Is Null Or
[forms]![frmDriver]![cmbDriver]. I think that I need to add the column
number but it will not let me. Is that what you were talking about?

Andy Cole said:
James

You're opening the Report and then opening the frmDriver in dialog mode. In
frmDriver, you select a Driver and then hide frmDriver. I don't see any
specific code to use the selected driver in your report. Have you set a
reference to Forms!frmDriver!cmbDriver in your report's recordsource
somewhere else?

Andy

James said:
I have a form that has one combo box with all of the employee's in it, and
later will add a date range. When I select the employee from the list and
then hit the view report button nothing is diplayed and no error messages.
If I don't have an employee in it it shows the error message to select the
employee like I want. The code is below for both the form and the report.

This is from the Form:

Private Sub btnDriver_Click()
If IsNull([cmbDriver]) Then
MsgBox "You must select a driver's name from the list."
DoCmd.GoToControl "cmbDriver"
Else
Me.Visible = False
End If
End Sub


This is from the report:

Private Sub Report_NoData(Cancel As Integer)
MsgBox "There is no data for this report. Canceling report..."
Cancel = -1
End Sub

Private Sub Report_Close()
DoCmd.Close acForm, "frmDriver"
End Sub

Private Sub Report_Open(Cancel As Integer)
DoCmd.OpenForm "frmDriver", , , , , acDialog, "Driver"
If Not IsLoaded("Driver") Then
Cancel = True
End If
End Sub
 
A

Andy Cole

James

The Report's RecordSource is the query or table where the Report gets its
records from. It would appear that you have set a reference as you state
"...in the query under EmployeeId: Is Null Or
[forms]![frmDriver]![cmbDriver]..."

As to why the report has missing dates for the selected Employee, I cannot
provide an answer as I do not know what your query is. I would suggest that
you make a copy of the report's query and change the Employee condition to a
fixed value, for example, EmployeeID: 1 ( or the ID of a particular
'Driver') and check whether the query returns the correct results.

HTH

Andy

James said:
I change the "driver" to "frmdriver" and that worked. However, when I open
the query for the report all of the dates are there and the employee that I
entered is there aswell. Thats what is should be. When I open the report
all of the dates are there except the dates that match for the selected
empoloyee. Any reason for this?

I don't know what you are talking about when you say reference in the
reports recordsource. I have in the query under EmplpoyeeId: Is Null Or
[forms]![frmDriver]![cmbDriver]. I think that I need to add the column
number but it will not let me. Is that what you were talking about?

Andy Cole said:
James

You're opening the Report and then opening the frmDriver in dialog mode. In
frmDriver, you select a Driver and then hide frmDriver. I don't see any
specific code to use the selected driver in your report. Have you set a
reference to Forms!frmDriver!cmbDriver in your report's recordsource
somewhere else?

Andy

James said:
I have a form that has one combo box with all of the employee's in it, and
later will add a date range. When I select the employee from the list and
then hit the view report button nothing is diplayed and no error messages.
If I don't have an employee in it it shows the error message to select the
employee like I want. The code is below for both the form and the report.

This is from the Form:

Private Sub btnDriver_Click()
If IsNull([cmbDriver]) Then
MsgBox "You must select a driver's name from the list."
DoCmd.GoToControl "cmbDriver"
Else
Me.Visible = False
End If
End Sub


This is from the report:

Private Sub Report_NoData(Cancel As Integer)
MsgBox "There is no data for this report. Canceling report..."
Cancel = -1
End Sub

Private Sub Report_Close()
DoCmd.Close acForm, "frmDriver"
End Sub

Private Sub Report_Open(Cancel As Integer)
DoCmd.OpenForm "frmDriver", , , , , acDialog, "Driver"
If Not IsLoaded("Driver") Then
Cancel = True
End If
End Sub
 

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