R
Robert Neville
Some people may be familiar with my import quest, so this question may
sound familiar. After months of developing my parsing routine, now I
want to programmatically append or update the import data into my
table. Queries do not allow the extent of control that queries and
code provide. Plus, append queries unnecessarily increment the auto
number field in my scenario. So the main objective involves append
and update import data from a repository table into the main table
while adding information whether the data is new or updated (and what
data was updated).
My research and reading has found several approaches utilizing forms;
yet my situation does not use any form. The import data goes from a
table repository to the main table; executed through code (maybe a
command button on a form in the future for execution).
Table Repository -> tblImportProdData
Main Table -> tblProj
My initial ideas involve using the Do While Loop to move through
tblImportProdData. Then check if the ProjName exists in the main
table; if it does not exist add the new record; if it exist then
update it. The second objective would involve tracking modified data;
yet this directive may be too ambition at this juncture.
Let me know if you have additional insights that may lead me into the
right direction. Here's my very crude initial code.
Private Sub UpdateProjects()
Dim dbs As Database
Dim rst As Recordset
Dim rstImport As Recordset
Const cstrProc As String = "UpdateProjects"
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("tblProj", dbOpenDynaset)
Set rstImport = dbs.OpenRecordset("tblImportProdData",
dbOpenDynaset)
Do While Not rstImport.EOF
rst.FindFirst "ProjName =" & rstImport!ProjName ' I am STUCK
here
'should I use Dlookup instead FindFirst
If rst.NoMatch Then
With rst
.AddNew
!ProjName = rstImport!ProjName
' various fields to update
!Update = "New"
.Update
End With
rst.Close
Set rst = Nothing
Set dbs = Nothing
DoCmd.Hourglass False
DoCmd.Echo True
Else
With rst
.Edit
!ProjName = rstImport!ProjName
' various fields to update
!Update = "Updated"
.Update
End With
rst.Close
Set rst = Nothing
Set dbs = Nothing
DoCmd.Hourglass False
DoCmd.Echo True
End If
Loop
End Sub
sound familiar. After months of developing my parsing routine, now I
want to programmatically append or update the import data into my
table. Queries do not allow the extent of control that queries and
code provide. Plus, append queries unnecessarily increment the auto
number field in my scenario. So the main objective involves append
and update import data from a repository table into the main table
while adding information whether the data is new or updated (and what
data was updated).
My research and reading has found several approaches utilizing forms;
yet my situation does not use any form. The import data goes from a
table repository to the main table; executed through code (maybe a
command button on a form in the future for execution).
Table Repository -> tblImportProdData
Main Table -> tblProj
My initial ideas involve using the Do While Loop to move through
tblImportProdData. Then check if the ProjName exists in the main
table; if it does not exist add the new record; if it exist then
update it. The second objective would involve tracking modified data;
yet this directive may be too ambition at this juncture.
Let me know if you have additional insights that may lead me into the
right direction. Here's my very crude initial code.
Private Sub UpdateProjects()
Dim dbs As Database
Dim rst As Recordset
Dim rstImport As Recordset
Const cstrProc As String = "UpdateProjects"
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("tblProj", dbOpenDynaset)
Set rstImport = dbs.OpenRecordset("tblImportProdData",
dbOpenDynaset)
Do While Not rstImport.EOF
rst.FindFirst "ProjName =" & rstImport!ProjName ' I am STUCK
here
'should I use Dlookup instead FindFirst
If rst.NoMatch Then
With rst
.AddNew
!ProjName = rstImport!ProjName
' various fields to update
!Update = "New"
.Update
End With
rst.Close
Set rst = Nothing
Set dbs = Nothing
DoCmd.Hourglass False
DoCmd.Echo True
Else
With rst
.Edit
!ProjName = rstImport!ProjName
' various fields to update
!Update = "Updated"
.Update
End With
rst.Close
Set rst = Nothing
Set dbs = Nothing
DoCmd.Hourglass False
DoCmd.Echo True
End If
Loop
End Sub