RE: Why can't I open a report using VB?



Hmm, still nothing I'm afraid. At the moment I'm trying to make it work with
the variable intTestID, but it still throws up a blank report with just
headings. It works when I call the report straight from the database window
and I enter the variable manually, but not when it's opened from the code. My
code is currently this:

If x = Forms!frmDrive!txtStations.Value Then
intTestID = Forms!frmDrive!Text35.Value
DoCmd.OpenReport "rptTest", acViewNormal, , "[TestID]=" & intTestID,
acWindowNormal
DoCmd.Close acForm, "frmTestTx", acSaveYes
DoCmd.Close acForm, "frmDrive", acSaveYes
Else
MsgBox "You have not entered enough transmitting sites!", vbOKOnly
Resume Exit_Command12_Click
End If

The name of the report has changed because I tried re-wizarding it.

"Stuart At Work" wrote:

Hi Sam,

It does look like the line opening the report is the problem. I'm guessing
that the report you're trying to open is based on a query or a table, and
that you're trying to filter the records displayed on the report to those
that match the value of "TestID". Is "TestID" a control on the form that
opens the report, or have you stored it in your variable intTestID?

If it's a control on the form (and the control is called TestID) then change
it to...

DoCmd.OpenReport stDocName, acViewNormal, , "[TestID]=" & Me.TestID,
acWindowNormal


If it's the variable intTestID then change it to...

DoCmd.OpenReport stDocName, acViewNormal, , "[TestID]=" & intTestID,
acWindowNormal

Hope this helps,


Stuart

"Sam Hayler" wrote:

Sorry! Here's the code:

Private Sub Command12_Click()
On Error GoTo Err_Command12_Click
If x = Forms!frmDrive!txtStations.Value Then
intTestID = Forms!frmDrive!Text35.Value
DoCmd.Close
DoCmd.Close
Dim stDocName As String
stDocName = "rptTest1"
DoCmd.OpenReport stDocName, acViewNormal, qryTest,
Queries!qryTest!TestID = TestID, acWindowNormal
Else
MsgBox "You have not entered enough transmitting sites!", vbOKOnly
Resume Exit_Command12_Click
End If

Exit_Command12_Click:
Exit Sub

Err_Command12_Click:
MsgBox Err.Description
Resume Exit_Command12_Click

End Sub

I kept the whole stDocName from the button wizard, and just added some code
around it, and now it doesn't work. It doesn't help that the error message is
so vague, it doesn't even have a de-bug button so I can see where the problem
is exactly. Howvere, when I comment out the line starting "DoCmd.OpenReport",
it executes the other code fine, so I'm assuming the problem is with that
line, unless there is something I need to declare and haven't...

"Stuart At Work" wrote:

Hi Sam,

Opening reports isn't a problem with VBA, so it sounds like there's a
problem with the code you've added. You'll need to post the code as there's
no way to fix it unless we can see it!

Cheers,


Stuart


"Sam Hayler" wrote:

Here's my problem:

If I make a button on my form to open a report using a wizard, this works
fine. However, when I add additional code and then use the button it shows an
error stating simply "Object Required", with no other information and only an
OK button. What is going on???
.


Loading