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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DAO question 1

Status
Not open for further replies.

sabavno

Programmer
Jul 25, 2002
381
CA
hi,

How can open two tables using DAO and then take a value of the field from one table and assign this value to the field of another table?
 
That's a big question. What criteria define which records the value is assigned to, how are the tables related etc? Basically you should open a recordset according to a query which combines the two tables and you could then use SQL to assign the value(s). But exactly how this is done depends on the relationship between the table sand how you choose what values go where etc. Have fun! :eek:)

Alex Middleton
 
I believe what you need to do is to use a DAO.Recordset to open each table, then using DAO methods synchronize them and perform your assignments.


Dim rst1 As DAO.Recordset
Dim rst2 As DAO.Recordset
Dim strSQL As String
Dim strCriteria As String

strSQL = "Your SQL here"
Set rst1 = CurrentDb.OpenRecordset(strSQL)
strSQL = "Your new SQL here:
Set rst2 = CurrentDb.OpenRecordset(strSQL)

If rst1.RecordCount <> 0 Then
rst1.MoveFirst
Else
MsgBox &quot;No data found.&quot;
GoTo Exit_Proc
End If

If rst2.RecordCount <> 0 Then
rst2.MoveFirst
Else
MsgBox &quot;No data found.&quot;
GoTo Exit_Proc
End If

Do While Not rst1.EOF
strCriteria = &quot;ID = '&quot; & NHA & &quot;'&quot;
rst2.FindFirst strCriteria
LookForMore:
If Not rst2.NoMatch Then
' Do your assignment thing here
Else
' Maybe write something out to a log file
' about this no match condition

' Maybe even continue to find matches
' rst1.FindNext strCriteria
' GoTo LookForMore
End If
DoEvents
rst1.MoveNext
Loop
----------------------
scking@arinc.com
Life is filled with lessons.
We are responsible for the
results of the quizzes.
-----------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top