RE: Why can't I open a report using VB?
- From: Stuart At Work <StuartAtWork@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 21 Jun 2006 05:53:02 -0700
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???
- Follow-Ups:
- RE: Why can't I open a report using VB?
- From: Sam Hayler
- RE: Why can't I open a report using VB?
- References:
- RE: Why can't I open a report using VB?
- From: Stuart At Work
- RE: Why can't I open a report using VB?
- From: Sam Hayler
- RE: Why can't I open a report using VB?
- From: Stuart At Work
- RE: Why can't I open a report using VB?
- From: Sam Hayler
- RE: Why can't I open a report using VB?
- Prev by Date: RE: Why can't I open a report using VB?
- Next by Date: RE: Why can't I open a report using VB?
- Previous by thread: RE: Why can't I open a report using VB?
- Next by thread: RE: Why can't I open a report using VB?
- Index(es):
Loading