Hello,
I just started learning vba not too long ago and I'm doing this project. What I have to do is import a table named ImportTable into the Project Master File table, but only updating the records in ImportTable that are different then whose of Project Master File.
'open the database and set the two recordset
Set dbs = OpenDatabase("C:\My Documents\Access\TestDatabase.mdb"
Set rstImport = dbs.OpenRecordset("SELECT * FROM ImportTable"
Set rstMaster = dbs.OpenRecordset("Select * FROM [Project Master File]"
'Import data from Temp table to the Project Master File if the Project ID equals the Project PS ID
Dim intI As Integer
intI = 1
With rstImport
Do Until .EOF
.Edit
If ![Project ID] = rstMaster![Project PS ID] Then
![Project Description] = rstMaster![Project/Service/Description]
![Project Manager] = rstMaster![Project Manager]
![Status] = rstMaster![Project Status]
![Roll Up Code] = rstMaster![RollUp Code]
![Customer ID] = rstMaster![Client PS ID]
![Project Start Date] = rstMaster![Project Start Date]
![Project End Date] = rstMaster![Project Close Date]
![CSP Billed This Year] = rstMaster![Billed This Year]
![CSP Billed Previous Years] = rstMaster![Billed Previous Years]
MsgBox "Error Checking", vbInformation, "Error Checking"
.Update
.MoveNext
intI = intI + 1
Else
MsgBox "The was a Error Importing Please try again", vbCritical, "Error Importing"
End 'exit loop while error checking
End If
Loop
End With
Not sure if I went about this the right way but if you have nything that can help me that would be great!!
If you need me to explain it better let me know
Dutt
I just started learning vba not too long ago and I'm doing this project. What I have to do is import a table named ImportTable into the Project Master File table, but only updating the records in ImportTable that are different then whose of Project Master File.
'open the database and set the two recordset
Set dbs = OpenDatabase("C:\My Documents\Access\TestDatabase.mdb"
Set rstImport = dbs.OpenRecordset("SELECT * FROM ImportTable"
Set rstMaster = dbs.OpenRecordset("Select * FROM [Project Master File]"
'Import data from Temp table to the Project Master File if the Project ID equals the Project PS ID
Dim intI As Integer
intI = 1
With rstImport
Do Until .EOF
.Edit
If ![Project ID] = rstMaster![Project PS ID] Then
![Project Description] = rstMaster![Project/Service/Description]
![Project Manager] = rstMaster![Project Manager]
![Status] = rstMaster![Project Status]
![Roll Up Code] = rstMaster![RollUp Code]
![Customer ID] = rstMaster![Client PS ID]
![Project Start Date] = rstMaster![Project Start Date]
![Project End Date] = rstMaster![Project Close Date]
![CSP Billed This Year] = rstMaster![Billed This Year]
![CSP Billed Previous Years] = rstMaster![Billed Previous Years]
MsgBox "Error Checking", vbInformation, "Error Checking"
.Update
.MoveNext
intI = intI + 1
Else
MsgBox "The was a Error Importing Please try again", vbCritical, "Error Importing"
End 'exit loop while error checking
End If
Loop
End With
Not sure if I went about this the right way but if you have nything that can help me that would be great!!
If you need me to explain it better let me know
Dutt