I have an Access Form with various dropdowns. The form contains a report in a subform. The report is based on the following SQL statement which references the dropdowns on the main form:
SELECT imp_rule_CURRENT.target
,imp_rule_CURRENT.Phase
,imp_phase.SortOrder
,imp_rule_CURRENT.Solicitation
,imp_rule_CURRENT.Qualification
,imp_rule_CURRENT.Activity
,imp_rule_CURRENT.ClientLocation
,imp_rule_CURRENT.ProviderLocation
,imp_rule_CURRENT.Answer
,imp_rule_CURRENT.Comment
,imp_ActivityList_Test_PB_MetaversionC2.HeadingText
,imp_answer.full_name
,imp_answer.icon2
,imp_phase.Chapter
,tbl_Country.short_name
,IIf([Forms]![frm_ClientModel]![ckbYesOnly], InStr([Answer], "is_yes") > 0, - 1) AS Is_Yes
FROM imp_phase
INNER JOIN (
imp_answer INNER JOIN (
tbl_Country INNER JOIN (
imp_ActivityList_Test_PB_MetaversionC2 INNER JOIN imp_rule_CURRENT
ON imp_ActivityList_Test_PB_MetaversionC2.SignatureTagSet = imp_rule_CURRENT.Activity
) ON tbl_Country.ISO_Country = imp_rule_CURRENT.target
) ON imp_answer.code_name = imp_rule_CURRENT.Answer
) ON imp_phase.code_name = imp_rule_CURRENT.Phase
WHERE (
((imp_rule_CURRENT.target) = [Forms]![frm_ClientModel]![cmbCountry])
AND ((imp_rule_CURRENT.Phase)
LIKE IIf([Forms]![frm_ClientModel]![cmbPhase] = "ALL", "*", [Forms]![frm_ClientModel]![cmbPhase]))
AND ((imp_rule_CURRENT.Solicitation) = [Forms]![frm_ClientModel]![txt_Initiative])
AND ((imp_rule_CURRENT.Qualification) = [Forms]![frm_ClientModel]![txt_Qualification])
AND ((imp_rule_CURRENT.ClientLocation) = [Forms]![frm_ClientModel]![txt_MeetingLocation_Client])
AND ((imp_rule_CURRENT.ProviderLocation) = [Forms]![frm_ClientModel]![txt_MeetingLocation_Bank])
AND ((imp_rule_CURRENT.Answer) <> "is_not_applicable")
AND ((IIf([Forms]![frm_ClientModel]![ckbYesOnly], InStr([Answer], "is_yes") > 0, - 1)) = True)
)
ORDER BY imp_phase.SortOrder;
When I have form open and the following part of the SQL statement evaluates to True Like IIf([Forms]![frm_ClientModel]![cmbPhase]="ALL","*",[Forms]![frm_ClientModel]![cmbPhase])) the query, when opened manually, shows all results as I would expect. Yet the subform which is based on this query shows no results.
Question: Why does the subform not show any results and how can I get the subform to show them?
Update 2:
I have tested and found out that if I view the report upon which the subform is based, then the correct results show. As noted in a comment below, the subform report works as intended when I selected anything other than "ALL". Results are shown for every other item seleted in the subform, just not when I select the option "ALL". Those results are not shown in the subquery, yet oddly they do show if I open the report manualy. So perhaps the problem is somehow linked to the subform?
I still don't understand why this is the case, but the answer to my problem was that the query of the mainform had to be adjusted to include the new statement. despite the subform NOT being linked to the main form.
As noted in my update, when I opened the query manually it worked fine. When I opened the report that was based on the query it worked fine. Only when I tried to open the report through the subform did it not show the expected result.
This finally led me to the insight that perhaps, under certain circumstances, the record set that was being shown was restricted somehow.
The main form that I had set up was itself based on a query. I had not updated that query to contain the new Like IIf([Forms]![frm_ClientModel]![cmbPhase]="ALL","*",[Forms]![frm_ClientModel]![cmbPhase])) command. Despite my subform NOT being linked to the main one, it restricted the recordset available to display.
Are you re-querying the subreport after the update?
Your code should include something along these lines, where rvSubReportView is the sub-report object:
rvSubReportView.Report.Requery
This would be in the AfterUpdate() function for the main form's ComboBox control.
Related
I'm stuck with an x-file trying to do something simple that I did thousands of times but now fails in a weird way.
I have a parent form called TASKS and a subform called TASKS_LIST. They are populated with recordsets that share some fields. The two important fields here are BUNDLE_ID (long) and TASK_ID (long).
Depending on certaing condition I want to link the subform with the parent form by the field BUNDLE_ID or by the field TASK_ID.
This is how I do it ->
First, in another form, I open the TASKS form like this:
DoCmd.OpenForm "TASKS", , , mVntCrit, , , intType
Where mVntCrit filters the records in the form and intType is an int with two possible values (1,2) passed by as an openArgs.
Then, on the Form_Open event of the parent form I do this:
Dim intTypeAs Integer
intType= Nz(OpenArgs)
Select Case intType
Case 1
Me.TASKS_LIST.LinkChildFields = "BUNDLE_ID"
Me.TASKS_LIST.LinkMasterFields = "BUNDLE_ID"
Case 2
Me.TASKS_LIST.LinkChildFields = "TASK_ID"
Me.TASKS_LIST.LinkMasterFields = "TASK_ID"
End Select
When I execute the code it appears an error message on the instructions that changes the linked fields:
Runtime Error '2101'
The specified value is not valid for this property.
I've tried/checked:
Initialize first the property values with an empty string to reset
the linking fields.
Change the order of the instructions, changing the value of the LinkMasterFields property first (althoug in principle the child goes first).
Compile, compact and repair.
Checked that the fields to link are the same type and have no nulls.
Checked that the fields name are correct.
What am I doing wrong? What am I missing?
Thanks a lot.
I found the issue.
I realized that the code worked for some records and failed for other records. So I needed to know what's different between the records that work and those than do not work.
Ok, in the original form that opens de TASKS parent form, there is a list of elements from a table T1. In the TASKS and TASKS_LIST forms the table T1 joins with a table T2 by a field F.
When I open the TASKS form, I filter its records with a certain criterion being F=Some Id from T1. The thing is: there are some records where this Id exists in T1 but not in T2. Therefore, when I open and filter the TASKS form with an Id that does not exists in T2 the form return no records. If TASKS do not return any records, TASKS_LIST do not return any records either.
In that case, when TASKS_LIST return no records, if I try to meddle with properties of the form (in this case .LinkChildFields and .LinkMasterFields) an error happens. On the other hand, when TASKS_LIST return some records, I can alter the form properties without problem.
Therefore I deduce that accessing and altering some properties of forms that return no records is forbidden for some reason. It reminds me of the classic error when trying to access the value of a texbox in a form without records.
I am trying to get an understanding of what the syntax would be to access a specific field within a query that makes up a subform within another form.
Form > SubForm/Query > Field
The field I am trying to get access to a field called Berthed that operates as a Boolean field. Either the vessel is present or it is absent.
This is what I was trying and it does not work.
Me.Boat_Move_Prior_Week.SourceObject.berthed
In this case here is the breakdown
Me = current form
Boat_Move_Prior_Week = query
Berthed = field I am trying to access through the VBA
My final goal will be to create an If statement, that upon requery of the Form, will look at the Berthed field, and if the field is checked (vessel is present) do nothing, but if the field is unchecked (vessel is not present) then remove the vessel from the query.
To reach the field (on the subform) bound to the field berthed, this is the syntax (assuming the textbox on the subform also is named berthed):
IsBerthed = Me!NameOfSubformControl.Form!berthed.Value
Here an amazing guide to know how to deal with controls in main form and subforms:
Link
Aside from my syntax issues I should have been using False for the value. Thanks to the two posters above for getting me in the right direction.
If Me.Boat_Move_Prior_Week.Form!BERTHED.value = False Then
Me.Boat_Move_Prior_Week.SourceObject = ""
End If
I have a form called "frmExpedicao", it's record source is a query called "slcExpedicao" that requires two parameters in order to filter the data, that are taken from fields of form "frmExpedicao" itself. I set the default values to field "flt_dt_entrega" = Date (today) and "op_tp_solicitacao" = 1 ("Pedido"). In order to filter to work, I had to call "Me.Requery" on method "Form_Load" of "frmExpedicao". So far so good, it showing the orders to close today, how I need it. However, when I put this "frmExpedicao" on a tab of a menu, right after login it shows pop-ups of the query "slcExpedicao" asking for the parameters. Probably because the "Form_Load" from "frmExpedicao" hasn't been called yet. Because if I open the "frmExpedicao" first, then the menu, it works fine. Do you know to fix it?
Thanks in advance!
As suggested, I declared TempVars on login:
TempVars.Add "DataEntrega", Date
TempVars.Add "TipoSolicitacao", "Pedido"
And use them as criteria on the query:
[TempVars]![DataEntrega]
[TempVars]![TipoSolicitacao]
Also update their values and requery if user selected another filter:
[TempVars]![DataEntrega] = Me.flt_dt_entrega.Value
Me.Requery
If op_tp_solicitacao = 1 Then
[TempVars]![TipoSolicitacao] = "Pedido"
Else
[TempVars]![TipoSolicitacao] = "Amostra"
End If
Me.Requery
I'm trying to bind multiple tables together and have a subform display data based on my combobox (ID name = CbproductName) selection in a form named Form2. I'm using Ms office Access.
This is the query
SELECT Employee.EmpName, Employee.EmpCode, Employee.CompanyID, Employee.DeptID,
Employee.ComputerID, Software.ProductName
FROM Software
INNER JOIN (
(
Computer INNER JOIN Employee ON Computer.CompID = Employee.ComputerID)
INNER JOIN Application ON Computer.ComputerName=Application.[A-ComputerID]
)
ON Software.ID = Application.SoftwareID
WHERE Application.SoftwareID = Form2.CbProductName;
However it keeps prompting me to enter the parameter value when i run the form, and it doesn't display the result of the entered value. it also doesn't change according to the combobox selection.
Can someone point me at a direction to get it done?
In a query, reference a form by its name as a member of the Forms collection. And then reference the value of a control on that form using the control name. It should look like this pattern:
Forms!FormName!ControlName
In your query, change the Where clause to this:
WHERE Application.SoftwareID = Forms!Form2!CbProductName;
Then make sure to refresh that query in after update event of CbProductName. You indicated the query is used as the record source for a subform, so assuming the subform control is on the same form as the combo box, try this as the after update procedure:
Private Sub CbProductName_AfterUpdate()
Me!SubformControlName.Form.Requery
End Sub
Beware, the subform control name may not be the same as the name of the form it contains. Make sure you use the name of the control.
Looking for a second set of eyes to figure out my problem with an Access form filter. I created a search form, when filled in, appends search criteria to a string variable (strQuery) that is put in place to the [WhereCondition] for opening a form. However, when the script is ran, nothing comes up except for a filtered form with no records.
Here is the line that opens the form:
DoCmd.OpenForm "ADD_NEW_NCMR", , , strQuery
Before the line is ran, strQuery equals:
1=1 AND [NCMR].[NCMR_NUM] = '12-129'
The form name, and table.column combination are all correct. In fact, using the DCount function returns the result of 1, which is correct for this query, and returns the correct number for other queries as well. This makes me think that there is nothing wrong with the where condition.
DCount("[NCMR_NUM]", "NCMR", strQuery)
Check your form's Data Entry property. You can find it on the Data tab of the form's property sheet.
If Data Entry = Yes, the form will not display existing records.
Sounds like you want Data Entry = No, so that existing records which match your OpenForm WhereCondition will be displayed.