j6lemonade
New Member
- Joined
- May 27, 2010
- Messages
- 3
I'm not very familiar with Access and I'm learning vba in Excel.
Here's what I want to do:
Copy a column of text in Excel
Open an access DB and replace existing items in table with copied data
Open a query and copy and paste the results back into Excel
I'm doing this through an ActiveX macro activated with a button click.
I'm using office 07 but the DB is in 02-03 file format, if this makes a difference. My code stops running at the line: .DoCmd.RunCommand acCmdSelectAll and from examples I've seen online I thought this would work. Does anyone know what I'm doing wrong?
Also, when I "delete" the table items manually, I get a message asking if I want to delete XX number of records, and I select "yes". I don't know if I need extra code to bypass/affirm this prompt?
Thanks for the help.
Here's my code:
ActiveSheet.Range("A1:A" & ActiveCell.Row).Copy
ActiveSheet.Range("A1").Select
' This section retrieves the Vendor Data from the Database
Dim FilePath As String
Dim AccDatabase As Object
Dim counter As Integer
FilePath = "C:\Personal\Macros\PartSupplier.mdb"
Set AccDatabase = CreateObject("Access.Application")
With AccDatabase
.Visible = True 'Will change to False when macro works
.OpenCurrentDatabase FilePath
.DoCmd.OpenTable "tblFindParts"
.DoCmd.SetWarnings False
.DoCmd.RunCommand acCmdSelectAll
.DoCmd.RunCommand acCmdDelete
.DoCmd.RunCommand acCmdPaste
' Other code goess here to open query and copy and paste data
End With
Set AccDatabase = Nothing
Here's what I want to do:
Copy a column of text in Excel
Open an access DB and replace existing items in table with copied data
Open a query and copy and paste the results back into Excel
I'm doing this through an ActiveX macro activated with a button click.
I'm using office 07 but the DB is in 02-03 file format, if this makes a difference. My code stops running at the line: .DoCmd.RunCommand acCmdSelectAll and from examples I've seen online I thought this would work. Does anyone know what I'm doing wrong?
Also, when I "delete" the table items manually, I get a message asking if I want to delete XX number of records, and I select "yes". I don't know if I need extra code to bypass/affirm this prompt?
Thanks for the help.
Here's my code:
ActiveSheet.Range("A1:A" & ActiveCell.Row).Copy
ActiveSheet.Range("A1").Select
' This section retrieves the Vendor Data from the Database
Dim FilePath As String
Dim AccDatabase As Object
Dim counter As Integer
FilePath = "C:\Personal\Macros\PartSupplier.mdb"
Set AccDatabase = CreateObject("Access.Application")
With AccDatabase
.Visible = True 'Will change to False when macro works
.OpenCurrentDatabase FilePath
.DoCmd.OpenTable "tblFindParts"
.DoCmd.SetWarnings False
.DoCmd.RunCommand acCmdSelectAll
.DoCmd.RunCommand acCmdDelete
.DoCmd.RunCommand acCmdPaste
' Other code goess here to open query and copy and paste data
End With
Set AccDatabase = Nothing