LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Pass parametres from Excel to Access query

How would I pass information from an Excel VBA module to an Access
query using ADO? At the moment I can run the report if I hard code the
parameters into the query but that is a bit pointless.

I run this report in Access at the moment and have a user form setup
that allows the user to specify their own parameters. The report is
then output to an Excel spreadhseet. As I intend to further manipulate
the data in Excel it would be better if Excel could be in charge from
the start.

I have included the VBA code below.



Public Sub SavedQuery()

Dim objField As ADODB.field
Dim rsData As ADODB.Recordset
Dim lOffset As Long
Dim sxConnect As String

'Create the connection string
szConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=J:\linktolive\linktolive.mdb;"

'Create the recordset object and run the query
Set rsData = New ADODB.Recordset

rsData.Open "[ADOFalkirkPriorityArrivals]", szConnect,
adOpenForwardOnly, _
adLockReadOnly, adCmdTable

'Make sure we get records back
If Not rsData.EOF Then

'Dump the contents of the recordset onto the worksheet
Sheet1.Range("A2").CopyFromRecordset rsData
'Fit the column widths to the data
Sheet1.UsedRange.EntireColumn.AutoFit
Sheet1.UsedRange.EntireRow.RowHeight = 20


Else
MsgBox "Error: No records returned.", vbCritical
End If

'Close the recordset
rsData.Close
Set rsData = Nothing


End Sub

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
pass parameter to access query Bill Manville Links and Linking in Excel 4 May 1st 23 03:45 AM
Is there a way to pass parameters to a web query in excel daytonsupply Excel Programming 1 February 23rd 05 04:10 PM
How to pass a date in Excel to ms query Vince Excel Programming 0 June 16th 04 10:08 PM
How to pass a date in Excel to ms query Tom Ogilvy Excel Programming 0 June 16th 04 04:26 PM
Pass Parameter to Access Query Al Excel Programming 3 April 29th 04 10:15 AM


All times are GMT +1. The time now is 06:27 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"