RE: Programming Loop with SQL Update Query
- From: "Adam Turner via AccessMonster.com" <u14766@uwe>
- Date: Fri, 21 Oct 2005 13:19:34 GMT
John C Brainard wrote:
>the code field is declared as string. the actual code that i have to look
>for is #M#
>
>here is what i got when i tried to run that:
>
>Runtime Error '3075'
>Syntax error in date in query expression 'ImportTable.Field38 = #M#'.
>
>here is the code that was run
>
> For CodeNum = 38 To 100
> CodeNum1 = "ImportTable.Field" & (CodeNum)
> CodeNum2 = "ImportTable.Field" & (CodeNum + 1)
> CodeNum3 = "ImportTable.Field" & (CodeNum + 2)
> CodeNum4 = "ImportTable.Field" & (CodeNum + 3)
> CodeNum5 = "ImportTable.Field" & (CodeNum + 4)
> CodeNum6 = "ImportTable.Field" & (CodeNum + 5)
> CodeNum7 = "ImportTable.Field" & (CodeNum + 6)
> CODE = "#M#"
>
>
> SQL = "INSERT INTO [M-Detail Table] ( ID, AccountNumber,[M-Detail1],
>[M-Detail2], [M-Detail3], [M-Detail4], [M-Detail5], [M-Detail6], [M-Detail7]
>)" & _
> "SELECT ImportTable.ID, ImportTable.AccountNumber, " &
>CodeNum1 & "," & CodeNum2 & "," & CodeNum3 & "," & CodeNum4 & "," & CodeNum5
>& "," & CodeNum6 & "," & CodeNum7 & " " & _
> "FROM [ImportTable] " & _
> "WHERE " & CodeNum1 & " = " & CODE
>
>> I'm not sure, but I think that what you are looking for is
>>
>[quoted text clipped - 59 lines]
>> >
>> > End Function
Your INSERT is running on every iteration whether or not #M# contains a valid
record.
By adding an IF...THEN scenario to determine whether or not the INSERT should
run might resolve the run-time error that might be caused by populating #M#
as NULL. If this is your intention, make sure the destination field/table
allows a NULL value.
Else add the following
For CodeNum = 38 To 100
CodeNum1 = "ImportTable.Field" & (CodeNum)
CodeNum2 = "ImportTable.Field" & (CodeNum + 1)
CodeNum3 = "ImportTable.Field" & (CodeNum + 2)
CodeNum4 = "ImportTable.Field" & (CodeNum + 3)
CodeNum5 = "ImportTable.Field" & (CodeNum + 4)
CodeNum6 = "ImportTable.Field" & (CodeNum + 5)
CodeNum7 = "ImportTable.Field" & (CodeNum + 6)
CODE = "#M#"
If LEN("#M#") > 0 Or NOT ISNULL("#M#") THEN
SQL = "INSERT INTO [M-Detail Table] ( ID, AccountNumber,[M-Detail1]
,
[M-Detail2], [M-Detail3], [M-Detail4], [M-Detail5], [M-Detail6],
[M-Detail7]
)" & _
"SELECT ImportTable.ID, ImportTable.AccountNumber, " &
CodeNum1 & "," & CodeNum2 & "," & CodeNum3 & "," & CodeNum4 &
"," & CodeNum5
& "," & CodeNum6 & "," & CodeNum7 & " " & _
"FROM [ImportTable] " & _
"WHERE " & CodeNum1 & " = " & CODE
Else
Next CodeNum
End If
--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-modules/200510/1
.
- References:
- Programming Loop with SQL Update Query
- From: John C Brainard
- RE: Programming Loop with SQL Update Query
- From: Ofer
- RE: Programming Loop with SQL Update Query
- From: John C Brainard
- Programming Loop with SQL Update Query
- Prev by Date: RE: Programming Loop with SQL Update Query
- Next by Date: Re: Programming Loop with SQL Update Query
- Previous by thread: RE: Programming Loop with SQL Update Query
- Next by thread: Re: Programming Loop with SQL Update Query
- Index(es):
Relevant Pages
|