sql statement in VBA - help! (1 Viewer)

rincewind_wizzard

Registered User.
Local time
Today, 01:06
Joined
Feb 7, 2018
Messages
23
HI all,

I'm trying to assign a sequence number to certain rows in a table - only those where the Migrate? field a mapping table is marked as True. Can't get it to work. I get 'Invalid use of property' on the strsql at the start of the sql statement:

sub testit()

'Now add the sequence number
Dim d As Database, r As Recordset, incnum As Long, strsql As Recordset

incnum = 1
Set d = CurrentDb
Set r = d.OpenRecordset("tblTrentSalaryElementsAll", dbOpenDynaset)

r.MoveFirst
Do Until r.EOF


strsql = "UPDATE tblTrentSalaryElementsAll LEFT JOIN tblMAPElements ON tblTrentSalaryElementsAll.[Permanent Element]" & _
"= tblMAPElements.TrentElement SET tblTrentSalaryElementsAll.SequenceNumber = incnum WHERE (((tblMAPElements.[Migrate?])=True));"

DoCmd.RunSQL strsql
incnum = incnum+1
r.MoveNext
Loop

r.Close

End Sub
 

MarkK

bit cruncher
Local time
Yesterday, 17:06
Joined
Mar 17, 2004
Messages
8,179
You have declared strsql as a recordset...
Code:
Dim d As Database, r As Recordset, incnum As Long, [COLOR="Blue"]strsql As Recordset[/COLOR]
...but you are assigning it a string value...
Code:
strsql = "UPDATE tblTrentSalaryElementsAll LEFT JOIN tblMAPElements ON tblTrentSalaryElementsAll.[Permanent Element]" & _
"= tblMAPElements.TrentElement SET tblTrentSalaryElementsAll.SequenceNumber = incnum WHERE (((tblMAPElements.[Migrate?])=True));"
hth
Mark
 

rincewind_wizzard

Registered User.
Local time
Today, 01:06
Joined
Feb 7, 2018
Messages
23
Oh good grief. It's late Friday afternoon - how could I not spot that. Thanks Mark.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 17:06
Joined
Aug 30, 2003
Messages
36,124
Post 3 was moderated, I'm posting to trigger email notifications.
 

MarkK

bit cruncher
Local time
Yesterday, 17:06
Joined
Mar 17, 2004
Messages
8,179
Paul, fwiw, post #1 was moderated too. Is there any rhyme or reason to what that is about?
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 17:06
Joined
Aug 30, 2003
Messages
36,124
There may be, but I don't always see it. Usually there is a link or something, but in this case I don't see why either post was moderated. Vassago or Jon may have a better idea of what goes on behind the curtain.
 

Users who are viewing this thread

Top Bottom