Fordraiders
asked on
pass through update query sql table using fieldname based on field selection in ListBox
2 tables:
tbl_Import_history
dbo_t_dispensing_metrics_d etail_sche dules
running an update query on sql table, for a specific field based on a selection of field names(field in sql table) in a list4 box.
is the following code correct ?
Thanks
fordraiders
tbl_Import_history
dbo_t_dispensing_metrics_d
running an update query on sql table, for a specific field based on a selection of field names(field in sql table) in a list4 box.
is the following code correct ?
'build the SQL string
strS = "UPDATE"
strS = strS & " dbo_t_dispensing_metrics_detail_schedules "
strS = strS & "SET "
strS = strS & "dbo_t_dispensing_metrics_detail_schedules.[Forms]![frm_Choice].[list4] = "
strS = strS & "[tbl_Import_Flag].[Field2] "
strS = strS & "tbl_Import_Flag INNER JOIN dbo_t_dispensing_metrics_detail_schedules ON tbl_Import_Flag.Field1;"
Thanks
fordraiders
ASKER
thanks will try it out !
You need two fields to match - like:
FROM
tbl1
INNER JOIN
tbl2
ON tbl1.SomeField = tbl2.SomeOtherField
/gustav
FROM
tbl1
INNER JOIN
tbl2
ON tbl1.SomeField = tbl2.SomeOtherField
/gustav
ASKER
OK,i did still error..
strS = "UPDATE "
strS = strS & "dbo_t_dispensing_metrics_ detail_sch edules "
strS = strS & "SET "
strS = strS & "dbo_t_dispensing_metrics_ detail_sch edules.[Fo rms]![frm_ Choice].[L ist4] = "
strS = strS & "[tbl_Import_Flag].[Field2 ] "
strS = strS & "FROM "
strS = strS & "tbl_Import_Flag INNER JOIN dbo_t_dispensing_metrics_d etail_sche dules.Acco unt_Number ON tbl_Import_Flag.Field1;"
This is a pass-through query and trying to update an sql table via odbc connection..as I stated in question.
Could this be causing a problem ?
fordraiders
strS = "UPDATE "
strS = strS & "dbo_t_dispensing_metrics_
strS = strS & "SET "
strS = strS & "dbo_t_dispensing_metrics_
strS = strS & "[tbl_Import_Flag].[Field2
strS = strS & "FROM "
strS = strS & "tbl_Import_Flag INNER JOIN dbo_t_dispensing_metrics_d
This is a pass-through query and trying to update an sql table via odbc connection..as I stated in question.
Could this be causing a problem ?
fordraiders
No, not by itself.
But as long as your syntax is non-SQL, it will fail - as explained in my previous post.
/gustav
But as long as your syntax is non-SQL, it will fail - as explained in my previous post.
/gustav
ASKER
The immediate window is showing this:
UPDATE dbo_t_dispensing_metrics_d etail_sche dules SET dbo_t_dispensing_metrics_d etail_sche dules."Dis engaged" = [tbl_Import_Flag].[Field2] FROM tbl_Import_Flag INNER JOIN dbo_t_dispensing_metrics_d etail_sche dules.Acco unt_Number ON tbl_Import_Flag.Field1;
The field Name from List4 has quotes around it ?
Thanks
fordraiders
UPDATE dbo_t_dispensing_metrics_d
The field Name from List4 has quotes around it ?
Thanks
fordraiders
Please, you need two fields to match - like:
FROM
tbl1
INNER JOIN
tbl2
ON tbl1.SomeField = tbl2.SomeOtherField
/gustav
FROM
tbl1
INNER JOIN
tbl2
ON tbl1.SomeField = tbl2.SomeOtherField
/gustav
ASKER
ok added this to get the field name properly.
strField = [Forms]![frm_Choice].[List 4].Value
strS = "UPDATE "
strS = strS & "dbo_t_dispensing_metrics_ detail_sch edules "
strS = strS & "SET "
strS = strS & "dbo_t_dispensing_metrics_ detail_sch edules." & strField & " = "
strS = strS & "[tbl_Import_Flag].[Field2 ] "
strS = strS & "FROM "
strS = strS & "tbl_Import_Flag INNER JOIN [dbo_t_dispensing_metrics_ detail_sch edules].[A ccount_Num ber] ON [tbl_Import_Flag].[Field1] ;"
still getting missing operator error ?
Thanks
fordraiders
strField = [Forms]![frm_Choice].[List
strS = "UPDATE "
strS = strS & "dbo_t_dispensing_metrics_
strS = strS & "SET "
strS = strS & "dbo_t_dispensing_metrics_
strS = strS & "[tbl_Import_Flag].[Field2
strS = strS & "FROM "
strS = strS & "tbl_Import_Flag INNER JOIN [dbo_t_dispensing_metrics_
still getting missing operator error ?
Thanks
fordraiders
ASKER
gustav, Go this to work. casting .
strS = "Update dbo_t_dispensing_metrics_d etail_sche dules as Res " & _
"Inner join tbl_Import_Flag as rand " & _
" on Res.Account_Number = Rand.Field1 " & _
"set Res." & strField & " = Rand.Field2 "
strS = "Update dbo_t_dispensing_metrics_d
"Inner join tbl_Import_Flag as rand " & _
" on Res.Account_Number = Rand.Field1 " & _
"set Res." & strField & " = Rand.Field2 "
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the help !!
You are welcome!
/gustav
/gustav
Open in new window
/gustav