PC Review


Reply
Thread Tools Rate Thread

Creating a Macro replacing data in Table with data in an Excel file

 
 
Shaun
Guest
Posts: n/a
 
      20th Oct 2005
This is what I'd like to do:

Have a button on my form that will import an excel file replacing the
data in my Access Table.

On my form I'd like to have a text box listing the file path of the
excel file. I want the user to have the ability to change the file path
through this text box. This way, if the excel file is moved the end
user can easily update the file path on the form.

Any Ideas?

 
Reply With Quote
 
 
 
 
=?Utf-8?B?S2xhdHV1?=
Guest
Posts: n/a
 
      20th Oct 2005
Here is a site that will give you the ability to open the common dialog box
without have to use an ActiveX control. It will allow the user to select the
file to open:

http://www.mvps.org/access/api/api0001.htm

Here is an example of how to use it:

Private Sub CmdImport_Click()
Dim varGetFileName As Variant

On Error GoTo ImportPipeline_Err

'Get the file to import
Do While True
varGetFileName = ahtCommonFileOpenSave(ahtOFN_OVERWRITEPROMPT, _
"\\rsltx1-bm01\busmgmt\Vought " & Me.txtCurrYear & "\Pipeline\", _
"Excel Spreadsheets (*.xls) *.xls", , _
"xls", Me!txtCurrYear & " " & Left(Me!cboPeriod.Column(1), 3) _
& " Pipeline.xls", "Select Pipeline", , True)
If varGetFileName = "" Then
If MsgBox("Cancel Import?", vbQuestion + vbYesNo, "Import
PipeLine") _
= vbYes Then
Exit Sub
End If
Else
Exit Do
End If
Loop

DoCmd.TransferSpreadsheet acLink, 8, "PipelineLink", _
varGetFileName, True, "80%!A3:P300"

MsgBox "Import Complete", vbOKOnly, "Import Pipeline"
ImportPipeline_Exit:
On Error Resume Next
DoCmd.DeleteObject acTable, "PipelineLink"
Exit Sub
ImportPipeline_Err:
If Err = 3011 Then
MsgBox varGetFileName & " is not a Pipeline File" _
& vbNewLine & "or is incorrectly formatted", vbCritical +
vbOKOnly, _
"Import Error"
Else
MsgBox Err.Number & " " & Err.Description, vbCritical + vbOKOnly,
"Import Error"
End If

End Sub

You can put this code in the Click event of the command button and it will
do what you want.

Put the code from the site above into a standard module per the instructions
so this code can call it.

"Shaun" wrote:

> This is what I'd like to do:
>
> Have a button on my form that will import an excel file replacing the
> data in my Access Table.
>
> On my form I'd like to have a text box listing the file path of the
> excel file. I want the user to have the ability to change the file path
> through this text box. This way, if the excel file is moved the end
> user can easily update the file path on the form.
>
> Any Ideas?
>
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Imported Data Not Replacing Existing Data - Excel 2007 Marilyn Microsoft Excel Misc 0 27th Apr 2009 05:22 PM
Creating a macro that reformats data in excel =?Utf-8?B?TCBIaWxs?= Microsoft Excel Programming 1 24th Sep 2007 09:06 AM
Loading data into Excel file from Data table. mpbalshetwar@gmail.com Microsoft Excel Programming 0 12th Aug 2006 12:17 AM
Creating a table from Excel data Richard Dean Microsoft Excel New Users 1 3rd Mar 2006 11:24 AM
Creating a pivot table from different sets of data using a macro =?iso-8859-1?Q?=C9idhne_in_Ireland?= Microsoft Excel Programming 1 21st Nov 2003 05:20 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:01 PM.