Reference a Subform in a Subform - ms-access

I have a report that has a Subreport. The Subreport references an ID that will populate the subreport. I keep getting an Enter Parameter Value error. If I put in the correct ID in the box and click ok the report populates correctly. So my assumption is that I have not referenced the ID correctly, but I can not figure out what I am doing incorrectly.
The report will work in the form until I insert it in to another form. I have a Navigation form called Main, a subform named ProductsList, and a subform inside of ProductsList called SupplierDS. The control name is ID. This is the reference I have:
[ID]=Forms![Main]![ProductsList].Form![SupplierDS].Form![ID]
Is this the correct reference to access the control ID?
This is the VBA code that I am using to reference the ID:
Private Sub Command524_Click()
Dim stDocName As String
stDocName = "SupplierDS"
DoCmd.OpenReport stDocName, acViewPreview, , "[ID]=Forms![Main]![ProductsList].Form![SupplierDS].Form![ID]"
End Sub

You can use string concatenation to make the statement work independent of where the form is:
DoCmd.OpenReport stDocName, acViewPreview, , "[ID] = " & Me!ID

Related

Using subform for report options

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 & "'"

How to get the ID of the row a command button is in (in MS Access Detail Section)

I have an MS Access 2003 form with a datasheet detail. I want to add "Print" button to each row which will open a detail report for that row.
Inside the Click handler, how do I access the ID of the row the button was in so I can pass it to the report?
Private Sub btnPrint_Click()
DoCmd.OpenReport "rptPrintDetails", acViewPreview, "", "Id=" & '<==== what goes here
End Sub
Use the Value property of the ID control on the form . Or, since the Value property is the default property, you can just use the name of the control.
For example, if you have a textbox control named "txtID", your code would say
DoCmd.OpenReport "rptPrintDetails", acViewPreview, "", "Id=" & Me.txtID

MS Access enter parameter value

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 & "'"

OpenArgs to Open a subform within a form?

I have an Access database with a Form that, once the EmployeeID is double-clicked, then it opens another form that contains a subform with employee information. I obtain the EmployeeID from the original form with this code...
myID = CInt(Me.OpenArgs)
I use this string on my secondary form and the subform contained within, however, it is not picking up the EmployeeID. The main form has this code for the Double-Click event...
Private Sub EmployeeID_DblClick(cancel As Integer)
Dim myID As Variant
myID = Me.EmployeeID
DoCmd.OpenForm "subformEmployeeInfo",,,,,,myID
DoCmd.OpenForm "frm_EmployeeInformation",,,,,,myID
End Sub
When I step through the code I notice that my ID is there on the OpenForm Command but when it switches to the subform code I get an "Invalid Use of Null" error.
With a subform, you can refer to the Parent OpenArgs,:
ID= Me.Parent.OpenArgs
These are the OpenArgs of the form on which the subform resides.

Is it possible to click on a report record to open relevant form in Access using VBA

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