Access to excel (1 Viewer)

Xproterg

Registered User.
Local time
Today, 12:58
Joined
Jan 20, 2011
Messages
67
Hello again,

I'm back for another learning experience. I've been programming with VBA for a few months now, and have hit another wall in my learning process.

The file I've attached is supposed to do a number of things. It's supposed to take a number of fields from a number of tables and export (append) those to an existing file.

The problem: It does export the data; however, when the data is exported, it is multiplied a number of times. So instead of ending up with 5 rows of data, I end up with 15 (or three sets of the same data).

The problem2: The data is not appended, it's overwritten. What is the fix for this? I know in languages like php, it's as simple as changing a switch in a function. I'm not sure it will be that simple in VBA.

Thank you for your time.
 

Xproterg

Registered User.
Local time
Today, 12:58
Joined
Jan 20, 2011
Messages
67
I don't see the attachment, so here it is. Also, here is the code:

PHP:
Option Compare Database
Private Sub Command9_Click()
'Dims begin here
Dim excelWS As String
Dim excelWB As String
Dim accessDB As String
Dim accessOBJ As Database
'Set path and worksheet
excelWB = CurrentProject.Path & "\xman.xls"
excelWS = "XMAN"
'Set path and database name
accessDB = CurrentProject.Path & "\Access2excell.accdb"
Set accessOBJ = OpenDatabase(accessDB)
'File null handler
If Dir(excelWB) = "" Then
MsgBox "File does not exist."
Else
accessOBJ.Execute _
"SELECT Table1.field1,Table1.field2,Table1.field3,Table2.field1 INTO [Excel 8.0;DATABASE=" & excelWB & _
"].[" & excelWS & "] FROM Table1,Table2"
accessOBJ.Close
Set accessOBJ = Nothing
End If
End Sub
 

Attachments

  • Access2excell.accdb
    876 KB · Views: 70

Users who are viewing this thread

Top Bottom