Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics
| Search | Today's Posts | Mark Forums Read
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 6th, 2006, 10:45 PM
Registered User
 
Join Date: Feb 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Export Access Paramter Query to Excel

Hello,

I have used Access for quite a while, but I am new to Visual Basic. Right now, I am trying to Automate my database by exporting the results of a parameter query to Excel. The criteria for the parameter query is based on a combo box I have loaded onto the form. How do I execute the parameter query (based on my combo box) and have the data automatically exported to an Excel template I have already created? I would like to automate this as much as possible with the combo box and parameter query. Thanks.

Justin
 
Old February 10th, 2006, 08:58 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Hi,

   Please post in Microsoft Office > Access VBA for better results.

You can put the parameter directly in the query in design view. Enter the following sort of code in the Criteria of the field you want to pass the parameters to:

[Forms]![frmMyForm].[cboMyComboBox]

Then use the button to open the form or report based on this query, and the query will go get the parameter from the combo box itself.

The downside is that this version of the query can only be used for this one button. If you want to pass the parameter to one version fo the query for all uses, then you would do this:

Dim stDocName As String
Dim inComboValue As Integer ' assumes PK is integer is being passed
Dim stLink As String

If IsNull(Me.MyComboBox) or Me.MyComboBox = "" Then
   'error handling
   Else
   inComboValue = Me.MyComboBox
End If

stLink = "[MyPK] = " & inComboValue
stDocName = "frmMyForm" 'or "rptMyReport"

DoCmd.Open... stDocName, , , stLink ' in the WHERE section

HTH


mmcdonal




Similar Threads
Thread Thread Starter Forum Replies Last Post
Export Access queries to Excel Spymaster Access VBA 2 August 18th, 2006 11:21 AM
Export an Access query to Excel Peter Martin Access 5 June 8th, 2006 06:36 AM
Entering Multiple Parameters in a Paramter Query jjc9809 Access 2 February 15th, 2006 09:36 PM
Export Access Data to a Specific Cell in Excel. VBNoob Access VBA 1 December 14th, 2005 08:25 PM
Export Table from Access to Excel aramchan Access VBA 2 July 12th, 2004 03:20 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.