Export from Office 2003 Excel to Access



I created an Excel spreadsheet as a template for employee data that multiple
supervisors rename and daily put data into concerning their employees. I
want to create a macro in the Excel template so that the supervisors can
daily export the employee data in their spreadsheet to a particular table in
a multi-user multi-purpose Access database. The data to be exported for each
day can be put into a contiguous area with the Access key field (employee ID)
as the first field and the date as the second field. The only qualification
would be to ask if you want to replace data that has the same employee ID and
date. There is always the possibility that two supervisors might be doing
the export at the same time, but they would not have the same employees.




I will try this. The only thing that appears to be missing is if it finds a
record in the Access table with the same first and second fields (employee ID
and date) I need to describe the data in a messagebox and ask if you want to
replace it, then act on a yes or no choice and move on to the next record.
Such as "404444 already exists on 6/26/09, do you want to replace it?"


Right! You could do that, or import everything; the data is automatically
appended under the last used record. Then run an update query, to delete
dupes. Check this out:



What you described would probably take a looooooong time, especially if you
are importing lots of dupes, right. Or, maybe I missed something...

Finally, you could use code such as this:
Private Sub Command1_Click()
Dim err As Integer
Dim cnn1 As ADODB.Connection
Dim rsttblPatient As ADODB.Recordset
Dim strCnn As String
'Dim mydb As DAO.Database
Dim mydb As String

'if no errors insert data
If err < 1 Then
' Open a connection.
Set cnn1 = New ADODB.Connection
mydb = "C:\RTDA Tool.mdb"
strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mydb
'On Error GoTo S:
cnn1.Open strCnn

' Open contact table.
Set rsttblPatient = New ADODB.Recordset
rsttblPatient.CursorType = adOpenKeyset
rsttblPatient.LockType = adLockOptimistic
rsttblPatient.Open "tblPatient", cnn1, , , adCmdTable

'get the new record data
rsttblPatient!MR = MR
rsttblPatient!FirstName = FirstName
rsttblPatient!LastName = LastName
rsttblPatient!ConsultDate = ConsultDate


' Show the newly added data.
MsgBox "New patient: " & rsttblPatient!FirstName & " " &
rsttblPatient!LastName & " has been successfully added!!"

'close connections
'S: MsgBox "An error has occurred. Please close the database, reopen, and
try again."

MsgBox "An Error has occurred, please check and try again"
End If

End Sub

That will automatically search for matching records:
#1) if the record is in the table, data will be UPDATED
#2) if the record is not in the table, data will be ADDED





Each supervisor has 10-20 employees, and this is a once-a-day report on their
employees. The only time there could be duplicates is if a correction needed
to be made, usually only to a few employees, after the data was originally
sent, and that doesn't happen very often. No big deal. So each employee
ultimately has only one record per day. We definitely don't want to confirm
the data transfer for each one, just the completion of the task.

I will try to adapt what you sent and see how it works.

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question