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

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



So just to clarify things, you now have no criteria in the query that refers
to the control on the form? If that's the case, then what we now need to do
is to check that the control that you refer to to populate the variable
"intTestID" is correct.

The query used to refer to "Forms!frmDrive!TestID", but the variable in the
code refers to "Forms!frmDrive!Text35". So both refer to controls on the
"frmDrive" form, but the controls are different - we need to find out which
(if either) is the correct one. Open your form in design view, and make a
note of the name of the control that you want to use for the criteria. Next
go to the code, and change the "Text35" section of the line of code below to
the name of the control that you made a note of.

intTestID = Forms!frmDrive!Text35.Value

Cheers,


Stuart


"Sam Hayler" wrote:

Sorry, I was mistaken. It used to ask for a variable because I tried to
directly compare TestID in the query with the control in the form, so if I
didn't open it from the form it asked for a value for
"Forms!frmDrive!TestID". I re-ran the wizard on the query as well though, to
see if that was the problem, and took the criteria out.

Sam

"Stuart At Work" wrote:

When you open the report from the database window and enter the variable
manually what does it ask for - is it "TestID"?

Cheers,


Stuart
"Sam Hayler" wrote:

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???
.



Relevant Pages

  • RE: Why cant I open a report using VB?
    ... You'll also get a message box telling you the value of the txtID control - ... Run the query to see if it returns any records. ... know that the query is fine, and so is the data that the report is based on. ... intTestID = Forms!frmDrive!Text35.Value ...
    (microsoft.public.access.modulesdaovba)
  • RE: Why cant I open a report using VB?
    ... Right, plugging the number into the criteria works, so the query itself is ... "Stuart At Work" wrote: ... know that the query is fine, and so is the data that the report is based on. ... is to check that the control that you refer to to populate the variable ...
    (microsoft.public.access.modulesdaovba)
  • RE: Filter Query by Year on a form
    ... If the check box does not affect what data are retrieved by the query, ... launch several different reports. ... it will launch that particular report say material cost report or ... If the user enters a year in the from year control and nothing in the to ...
    (microsoft.public.access.queries)
  • Re: Count to 8 and start over
    ... Use the report capability to produce a running sum, not the query, so the query will be 'easier'. ... In the report, appropriate section, add a textbox control, make its control source = 1, and make its running sum property to yes. ...
    (microsoft.public.access.queries)
  • Re: Change of field name causes application to crash
    ... I can create a simple Sum query and get the same crash. ... UNION ALL query to simply UNION. ... > are part of the report. ... Sometimes when you have a control ...
    (microsoft.public.access.modulesdaovba)