Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

update a single table within a multiple table recordset

Status
Not open for further replies.

doquigley

Technical User
Jan 16, 2006
12
0
0
IE
MS Access does it
VBA does it
VB6?

I am linked to a MS SQL Server Database and my vba knowledge is of no use. I try the 2 following methods but neither work

An update recordset which has more than one table linked but only updating a single field does not work

Set objRs = New ADODB.Recordset
sSql = "UPDATE TempCollectables INNER JOIN SourceDest ON TempCollectables.SourceId = SourceDest.SourceId SET TempCollectables.SourceDestTypeId = [SourceDest]![SourceDestCode] WHERE (((SourceDest.SourceDestGroup)='" & "Intercompany" & "'));"
objRs.Open sSql, objConn, adOpenStatic, adLockOptimistic
Set objRs = Nothing


A select recordset based on more than one table with a step through and then update on a single field does not work

Set objRs = New ADODB.Recordset
sSql = "SELECT SourceDestCode, SourceDestTypeId FROM TempCollectables INNER JOIN SourceDest ON TempCollectables.SourceId = SourceDest.SourceId WHERE (SourceDest.SourceDestGroup ='" & "Intercompany" & "');"
objRs.Open sSql, objConn, adOpenStatic, adLockOptimistic
If Not objRs.EOF Then
'objRs.MoveFirst
Do While Not objRs.EOF
objRs!SourceDestTypeId = objRs!SourceDestCode
objRs.Update
objRs.MoveNext
Loop
End If
Set objRs = Nothing


How do I get around this or am I missing something

Cheers, a really helpful site

 

How about something like:
Code:
    [blue]Dim strUpdate As String[/blue]
    Set objRs = New ADODB.Recordset
    sSql = "SELECT SourceDestCode, SourceDestTypeId FROM TempCollectables INNER JOIN SourceDest ON TempCollectables.SourceId = SourceDest.SourceId WHERE (SourceDest.SourceDestGroup ='" & "Intercompany" & "');"
    objRs.Open sSql, objConn, adOpenStatic, adLockOptimistic
    If Not objRs.EOF Then
        'objRs.MoveFirst
        Do While Not objRs.EOF[blue]
            strUpdate = "Update TempCollectables Set " _
            & " SomeFiled = 'abc', OtherFiled = 123 " _
            & " Where someotherf = 'Whatever'"
            objConn.Execute strUpdate[/blue][green]
            'objRs!SourceDestTypeId = objRs!SourceDestCode
            'objRs.Update[/green]
            objRs.MoveNext
        Loop
    End If
    Set objRs = Nothing

Have fun.

---- Andy
 
Excellent Andy, Thank you so much for that

Queries within queries, where will it all end?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top