PDA

View Full Version : [SOLVED:] Converting SQL to a string



Marcster
11-04-2016, 06:36 AM
I'm trying to get a sql statement:
UPDATE tblName SET Table1.[Month] = MonthName([Trans Date],True);

converted to a string so I can pass the Table Name and Field Name (which is a Date field) to it which will update the Month field.

So far i have:
strSQL = "UPDATE " & strTableName & " SET Month = " & CStr(MonthName(Month(strFieldName))) & ";"

Which errors with: Run-time error '13' Type mismatch.

CurrentDb.Execute strSQL

Thanks,

SamT
11-05-2016, 08:24 AM
Moderator Bump

Marcster
11-07-2016, 03:04 AM
Resolved.

strSQL = "UPDATE " & strTableName & " SET " & strTableName & ".Month = MonthName(Month(" & strFieldName & "))" & "; "

SamT
11-07-2016, 07:59 AM
:thumb