Z
Zikar
Good day,
I am seeking help to resolve a query that I want to run from a class Module
in access 2003. I first designed the query by linking the two tables and set
the wanted criteria and then copied the query from SQL View and pasted it in
the Class Model which is as follows:
UPDATE Tbl_Risk_LocalProfiles LEFT JOIN
Tbl_Risk_LocalProfiles_ResponsiblePersons ON Tbl_Risk_LocalProfiles.ProfileID
= Tbl_Risk_LocalProfiles_ResponsiblePersons.ProfileID SET
Tbl_Risk_LocalProfiles_ResponsiblePersons.RO_ProfileStatus =
Tbl_Risk_LocalProfiles.Frame_ProfileStatus
WHERE
(((Tbl_Risk_LocalProfiles_ResponsiblePersons.RiskProjectID)=[Forms]![Risk_ProfilesProjectSelection]![Risk_ProfilesProjectSelection_Subform].[Form]![ProjectID])
AND
((Tbl_Risk_LocalProfiles_ResponsiblePersons.ProfileID)=[Forms]![Risk_ProfilesProjectSelection]![Risk_ProfilesProjectSelection_Subform].[Form]![txtProfileID])
AND
((Tbl_Risk_LocalProfiles_ResponsiblePersons.RiskPeriodID)=[Forms]![Risk_ProfilesProjectSelection]![Risk_ProfilesProjectSelection_Subform].[Form]![txtPeriod]));
I revised the UPDATE Query to run it as SQL in the Module by concatenating
the criteria to the SQL string. This method did previously work with SQL
Query Code in Form Module to Return Record Count. Steve Sanford who provided
me this help, explained to me that VBA can't evaluate the reference to the
subform and therfore I tried to do the same tequnique for the UPDATE Query in
the BeforeUpdate_Form property as follows:
Dim SQL As String
SQL = "UPDATE Tbl_Risk_LocalProfiles LEFT JOIN "
SQL = SQL & " Tbl_Risk_LocalProfiles_ResponsiblePersons ON"
SQL = SQL & " Tbl_Risk_LocalProfiles.ProfileID =
Tbl_Risk_LocalProfiles_ResponsiblePersons.ProfileID"
SQL = SQL & " SET Tbl_Risk_LocalProfiles_ResponsiblePersons.RO_ProfileStatus
= Tbl_Risk_LocalProfiles.Frame_ProfileStatus"
SQL = SQL & " WHERE (RiskProjectID = " & Me!ProjectID And ""
SQL = SQL & " ProfileID = " & Me!txtProfileID And ""
SQL = SQL & " RiskPeriodID= " & Me!txtPeriod & ";"
Debug.Print SQL
I have debugged the Code and did not obtain an error but the query does not
update the table when I run it as a code. However, it does run perfectly well
from the Query design only if I provide the criteria as values and not by
referencing the controls in the Form.
I am sure there is somthing wrong with the code and would greatly apprecite
help with this.
Cheers
I am seeking help to resolve a query that I want to run from a class Module
in access 2003. I first designed the query by linking the two tables and set
the wanted criteria and then copied the query from SQL View and pasted it in
the Class Model which is as follows:
UPDATE Tbl_Risk_LocalProfiles LEFT JOIN
Tbl_Risk_LocalProfiles_ResponsiblePersons ON Tbl_Risk_LocalProfiles.ProfileID
= Tbl_Risk_LocalProfiles_ResponsiblePersons.ProfileID SET
Tbl_Risk_LocalProfiles_ResponsiblePersons.RO_ProfileStatus =
Tbl_Risk_LocalProfiles.Frame_ProfileStatus
WHERE
(((Tbl_Risk_LocalProfiles_ResponsiblePersons.RiskProjectID)=[Forms]![Risk_ProfilesProjectSelection]![Risk_ProfilesProjectSelection_Subform].[Form]![ProjectID])
AND
((Tbl_Risk_LocalProfiles_ResponsiblePersons.ProfileID)=[Forms]![Risk_ProfilesProjectSelection]![Risk_ProfilesProjectSelection_Subform].[Form]![txtProfileID])
AND
((Tbl_Risk_LocalProfiles_ResponsiblePersons.RiskPeriodID)=[Forms]![Risk_ProfilesProjectSelection]![Risk_ProfilesProjectSelection_Subform].[Form]![txtPeriod]));
I revised the UPDATE Query to run it as SQL in the Module by concatenating
the criteria to the SQL string. This method did previously work with SQL
Query Code in Form Module to Return Record Count. Steve Sanford who provided
me this help, explained to me that VBA can't evaluate the reference to the
subform and therfore I tried to do the same tequnique for the UPDATE Query in
the BeforeUpdate_Form property as follows:
Dim SQL As String
SQL = "UPDATE Tbl_Risk_LocalProfiles LEFT JOIN "
SQL = SQL & " Tbl_Risk_LocalProfiles_ResponsiblePersons ON"
SQL = SQL & " Tbl_Risk_LocalProfiles.ProfileID =
Tbl_Risk_LocalProfiles_ResponsiblePersons.ProfileID"
SQL = SQL & " SET Tbl_Risk_LocalProfiles_ResponsiblePersons.RO_ProfileStatus
= Tbl_Risk_LocalProfiles.Frame_ProfileStatus"
SQL = SQL & " WHERE (RiskProjectID = " & Me!ProjectID And ""
SQL = SQL & " ProfileID = " & Me!txtProfileID And ""
SQL = SQL & " RiskPeriodID= " & Me!txtPeriod & ";"
Debug.Print SQL
I have debugged the Code and did not obtain an error but the query does not
update the table when I run it as a code. However, it does run perfectly well
from the Query design only if I provide the criteria as values and not by
referencing the controls in the Form.
I am sure there is somthing wrong with the code and would greatly apprecite
help with this.
Cheers