S
Scott
I am trying to UPDATE records in a table using variables
that get their values as the code is executed. I have
never been able to do this successfully, though it seems
it should be easy to do. I've always found a way to get
the values I need by either getting the values from
existing forms, or by creating forms and then getting the
values from them. Sometimes it is a cumbersome way to do
it and I am now at a point where I don't see a way to work
around it. Can you help me write code that will do what I
am trying to do?
Private Sub UpdateRecords_Click()
On Error GoTo Err_UpdateRecords_Click
Dim Entryidtemp As Integer
Dim relationidtemp As Integer
DoCmd.RunSQL "INSERT INTO Relationstemp (Entryid)
SELECT DISTINCT Relations.entryid FROM Relations WHERE
(((Relations.relationid)=6) AND ((Relations.category)=4))
OR (((Relations.relationid)=7) AND ((Relations.category)
=5));"
Set dbCurrent = CurrentDb
strSQL = "select * from relationstemp;"
Set rsrelationstemp = dbCurrent.OpenRecordset(strSQL)
rsrelationstemp.MoveFirst
Entryidtemp = rsrelationstemp!entryid
Do Until rsrelationstemp.EOF
rsrelationstemp.MoveNext
relationidtemp = rsrelationstemp!entryid
*** DoCmd.RunSQL "Update relationstemp set relationid =
relationidtemp where entryid = entryidtemp;" ***
Loop
Exit_UpdateRecords_Click:
Exit Sub
Err_UpdateRecords_Click:
MsgBox Err.Description
Resume Exit_UpdateRecords_Click
End Sub
This is the problem line:
DoCmd.RunSQL "Update relationstemp set relationid
= relationidtemp where entryid = entryidtemp;"
I want the code to pick up the variables set in the
previous lines, but when I execute the code (click the
button), I get a message asking for the parameters
relationidtemp and entryid temp. Any help you can give is
very much appreciated.
that get their values as the code is executed. I have
never been able to do this successfully, though it seems
it should be easy to do. I've always found a way to get
the values I need by either getting the values from
existing forms, or by creating forms and then getting the
values from them. Sometimes it is a cumbersome way to do
it and I am now at a point where I don't see a way to work
around it. Can you help me write code that will do what I
am trying to do?
Private Sub UpdateRecords_Click()
On Error GoTo Err_UpdateRecords_Click
Dim Entryidtemp As Integer
Dim relationidtemp As Integer
DoCmd.RunSQL "INSERT INTO Relationstemp (Entryid)
SELECT DISTINCT Relations.entryid FROM Relations WHERE
(((Relations.relationid)=6) AND ((Relations.category)=4))
OR (((Relations.relationid)=7) AND ((Relations.category)
=5));"
Set dbCurrent = CurrentDb
strSQL = "select * from relationstemp;"
Set rsrelationstemp = dbCurrent.OpenRecordset(strSQL)
rsrelationstemp.MoveFirst
Entryidtemp = rsrelationstemp!entryid
Do Until rsrelationstemp.EOF
rsrelationstemp.MoveNext
relationidtemp = rsrelationstemp!entryid
*** DoCmd.RunSQL "Update relationstemp set relationid =
relationidtemp where entryid = entryidtemp;" ***
Loop
Exit_UpdateRecords_Click:
Exit Sub
Err_UpdateRecords_Click:
MsgBox Err.Description
Resume Exit_UpdateRecords_Click
End Sub
This is the problem line:
DoCmd.RunSQL "Update relationstemp set relationid
= relationidtemp where entryid = entryidtemp;"
I want the code to pick up the variables set in the
previous lines, but when I execute the code (click the
button), I get a message asking for the parameters
relationidtemp and entryid temp. Any help you can give is
very much appreciated.