Can you see the value of txtID on the form when it's open normally? Make a
note of the value of it, close the form, and then open up the query that the
report is based on in design view. Find the field that you want to apply the
criteria to, and pop the value you made a note of from the form in the
criteria row. Run the query to see if it returns any records. This way we'll
know that the query is fine, and so is the data that the report is based on.
If that's all OK then it shouldn't be hard to sort out the form at all.
Stuart
:
Right, to avoid confusion I've changed the name of the text box and all
references to it to txtID. However, I still get the same problem. I'm
absolutely stumped.
Sam
:
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
:
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
:
When you open the report from the database window and enter the variable
manually what does it ask for - is it "TestID"?
Cheers,
Stuart
:
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.
:
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
:
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...
:
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
:
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???