I have a form and in the form is a sub form that displays rows from a query. One of the columns in the subform is the DNANumber. The report works 100%. Problem is, when I call the report using the following code,
strWhereClause = "[DNANumber]=" & strText
DoCmd.OpenReport "Certificate", acViewPreview, , strWhereClause, , acHidden
I get a popup message asking for the parameter value, also displaying that exact value it is looking for above the textfield. I have checked all the spelling in the queries, forms , subforms and tables and controlls. Everything is fine. Why do I get this popup message. Further, If I type in the value, it displays the report without a problem.
If [DNANumber] is text data type, add quotes around the value of strText when you build strWhereClause.
strWhereClause = "[DNANumber]='" & strText & "'"
Related
Pretty new at this. I have a main form with a list box of job numbers and a subform for the different reports. I want to be able to select a job name and then double click the report name to preview it but it gives me an error. It doesn't seem to recognize my selected job name from the list box. Error message is "Compile Error: Method or Data Member Not Found". See image.
Here is the code i'm using which is on the Double Click event on the text box in the subform.
Private Sub ReportName_DblClick(Cancel As Integer)
Dim strFilter As String
If IsNull(Me.lstJobName) Then
MsgBox "You Must Select A Job"
Me.lstJobName.SetFocus
Exit Sub
End If
strFilter = "JobName = '" & Me.lstJobName & "'"
DoCmd.OpenReport ReportName.Value, acViewPreview, , strFilter
End Sub
Trying to figure this out step by step so just need the report to preview for now. Later I will want to check off the reports that I need printed then just click a button to print.
The code is behind the subform therefore the Me. qualifier is alias for the subform and code is looking for the listbox on the subform but it is actually on the main form.
strFilter = "JobName = '" & Me.Parent.lstJobName & "'"
I have a button on my form that creates a print preview of my report. I can not get it to open on the same record as the current form. Instead it opens to the first record. They are both on the same query. I tried both macros and VBA. I'm new to access and cant understand how to get my records to be the same and print preview just the record I had open in my form
Here's my VBA code,I get error saying "no messsage for this error"
DoCmd.OpenReport "Moisture", acViewPreview, , "[Order Number]= " & [Order Number]
Try:
DoCmd.OpenReport "Moisture", acViewPreview, , "[Order Number]=""" & [Order Number] & """"
This may not be the best way but i solved this issue by creating a query for the report that only displayed the record source that was open with in my form. I passed the following in my criteria for my primary key in the query.
[Forms]![NameOfForm]![PrimaryKey]
thus only displaying that specific fields for that Primary key opened in the form and nothing else.
Still a beginning access programmer here. Trying to get the report to work. Here is what I am doing
I first created a report using the Report Wizard using the following query as input
SELECT EmployeeId, Project, StartDate
FROM Tasks;
I have a form wherein I select the employee-id. I want to filter the report based on the employee id selected. Here is what I have for invoking the report
DoCmd.OpenReport "rptEmpWork", acViewPreview, "qryEmpReport", "EmployeeId = " & strempid
qryEmpReport is the name of the query that holds the report query that I mentioned above. The strempid holds the value that was selected in the form. However when I get around to execute this, it prompts me to enter the employee id again. Any ideas as to why I am getting this? I have validated to make sure that the strempid does contain the value selected earlier.
I'll guess Tasks.EmployeeId is text datatype. If my guess is correct, add quotes around the value you supply for EmployeeId:
DoCmd.OpenReport "rptEmpWork", acViewPreview, "qryEmpReport", "EmployeeId = '" & strempid & "'"
Based on our trouble-shooting exercise in the comments, I think you should give yourself an opportunity to examine the actual string value you're giving to OpenReport for its WhereCondition argument. (It's better to view the actual string instead of trying to imagine what it looks like.)
Dim strWhereCondition As String
strWhereCondition = "EmployeeId = '" & strempid & "'"
Debug.Print "strWhereCondition ->" & strWhereCondition & "<-"
DoCmd.OpenReport "rptEmpWork", acViewPreview, "qryEmpReport", strWhereCondition
View the output from Debug.Print in the Immediate window; Ctrl+g will take you there.
I have a form which allows the user to edit the properties of a filter via some combo boxes, then open a report. The report is opened with
DoCmd.OpenReport rptName, acViewReport, , whereClause, acWindowNormal
'whereClause = "Building = '005'" for instance
Some reports open fine, by which I mean they populate with the filtered info. Others, however, even though they are based off the same in-house template, IGNORE the filter all together and display a report based on ALL data (not the filtered data).
Why would a report ignore the filter? When I edit the reports in design mode after opening them with the form:
Working Report | Non Working Report
Filter: Building = '005' | Filter:
Filter On Load: No | Filter On Load: No
What could be causing the non-working report to not register the filter argument? There's no On Load VBA, nor any VBA, in these reports (except for an Export to PDF and a close button which is copy-paste for each report).
EDIT
Should have checked before, this happens regardless of whether or not the query driving the report is empty (ie the filter is never applied to some reports, regardless of blankness)
Not sure if the code will help, but:
Private Sub btnOpenSummary_Click()
If IsNull(Me.cboSummary) Then
MsgBox "Please select a building for the SUMMARY report."
Exit Sub
End If
strCrit = "Building = '" & Me.cboSummary & "'"
MsgBox strCrit
survArray = getSurveyArray()
For Each Survey In survArray
DoCmd.OpenReport Survey, acViewReport, , strCrit, acWindowNormal
Next Survey
DoCmd.OpenReport "Total Summary", acViewReport, , , , Me.cboSummary
End Sub
My fault.. there was code which had for some reason been linefed all the way down the code page and out of view. There was an On Open which played with the Control Source. It ended up being useless (as the control source only needed to be set once, not every time) but it was disabling the filter for some reason. Anybody else who may have this problem:
Make sure the control source is not being altered in your VBA for the report.
Thanks to those that helped, sorry my information was wrong.
My OnOpen code:
Private Sub Form_Open(Cancel as Integer)
Me.RecordSource = Me.Name
End Sub
It takes the name of the report, which corresponds to a name of a query, and puts it as the recordsource. (I have about 40 reports done this way, so it's dependent on names to make it fast to duplicate for different items).
Removing this made it work perfectly using Access 2010. Not sure if this was a problem specific to my setup or what, but, this change directly fixed it.
This is not a direct solution, but rather a workaround which should almost certainly work. Instead of applying filtering to the report, dynamically change the report data source by passing the where clause as a parameter.
To open the report use:
DoCmd.OpenReport rptName, acViewReport, , , acWindowNormal, whereClause
Note that the whereClause string is being passed as the OpenArgs parameter.
Then in the report VB:
Private Sub Report_Open(Cancel As Integer)
On Error GoTo ReportOpenError
If Not(IsNull(Me.OpenArgs)) Then
Me.RecordSource = Replace(Me.RecordSource,";"," WHERE " & Me.OpenArgs & ";")
End If
Exit Sub
ReportOpenError:
MsgBox "Unable to open the specified report"
Cancel = 1
End Sub
This solution assumes the report RecordSource is defined as a semicolon terminated SQL query (not a query name) and the record source does not already contain any WHERE, GROUP BY, etc., clauses. In those cases, it may be easier to redefine the query from scratch.
This problem may also occur when a report is copied and re-purposed. I had a report that was working fine then made a copy of it and was no longer able to filter it.
Perhaps there is a glitch in Access that causes it to ignore the filter when the report is copied under certain circumstances.
Solution: Instead of copying and re-naming the report, try creating a new report, linking the data source, and copying the fields back into place. If you are dealing with a new report, try re-creating it.
I have a report with details of jobs/tasks, and also a form which contributes the majority of the data towards that report. Given that a report is a nice way of looking at the larger picture of the data, and a form is the best way of editing data, I would like to be able to click on a row, and have it open up the relevant record in the form view.
Does anyone know how to do this through VBA? In my mind it should be possible, though my knowledge of objects in Access is limited.
Update
I've implemented the following code for my report:
Private Sub Edit_Click()
Dim EntityName As String
Dim DocName As String
DocName = "Entity: Overview"
strWhere = "[Entity Name]='" & Entity & "'"
DoCmd.OpenForm DocName, acNormal, , EntityName
End Sub
It successfully opens the correct form, and it also grabs the correct entity name, however it isn't filtering properly. I can't see what the issue is with the code.
In your Edit_Click() procedure, you have EntityName as the WhereCondition parameter to OpenForm.
DoCmd.OpenForm DocName, acNormal, , EntityName
However, you haven't assigned anything to EntityName, so it's an empty string. I think you should use strWhere as the WhereCondition.
Private Sub Edit_Click()
Dim strWhere As String
Dim DocName As String
DocName = "Entity: Overview"
strWhere = "[Entity Name]='" & Me.Entity & "'"
DoCmd.OpenForm DocName, acNormal, , strWhere
End Sub
I assumed Entity is the name of a control, and that's where you get a value to build strWhere. If there is no control in the report by the name of Entity, then the code won't work even if there is an Entity in the original query.
You should be able to add an On Click event in the Detail section of the report, then add something like this in the VBA handler:
DoCmd.OpenForm "MyForm", acNormal, "", "ID=" & ID.Text
(where MyForm is the target form, and ID is a hidden or visible control in your report that identifies the current record).
You say report, but you should not be using a report but a continuous form or datasheet. You can then add events to any of the controls on any line, and add a double-click event, if you do not want to drive your users insane. You could also add a command button if that would be clearer to your users, or format the "link" textbox to underline. The record opened by the action shown by #dbaseman will open which even record has the focus (current record). And that will lead you to discover what you can and can't do with a continuous form :D