Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA 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 December 17th, 2003, 11:36 PM
Registered User
 
Join Date: Dec 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to set properties of query in Access VBA

I need to create a make-table query. The table will be created in another database. I can enter destination database when I set properties of the query in design view. But since the destination database may change each time(users can choose), how can i set this property of query in Access VBA.
Your help will be highly appreciated!

 
Old December 23rd, 2003, 12:43 PM
Authorized User
 
Join Date: Dec 2003
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You will have to use a variable and pass the variable using Code.

I wrote this to insert a string into a table on the fly using a users input. You can adapt it for what you need. Or at least get some ideas as to the direction you need to go:

Option Compare Database
Option Explicit

Dim strResponse As String
Dim strSQL As String

strResponse = InputBox("New table name?")

strSql = "INSERT INTO TblAccessDate ([Date],[Time],[TableName])" & _
         " VALUES (#" & CStr(Date) & "#, #" & CStr(Time) "#, '" & strSaveAs & "');"


 
Old September 27th, 2006, 08:42 AM
pjm pjm is offline
Authorized User
 
Join Date: Jul 2006
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That last response seems to have a few mystery variables thrown in. Try this:

    ' These 2 variables get their values from perhaps a form or an inputbox function (you decide)
    Dim Tablename as String
    Dim DatabasePath as String

    Dim qs as String

    qs = "SELECT <and some other stuff>"

    ' The key piece of code
    qs = qs & " FROM " & Tablename " AS T IN '" & DatabasePath & "'"

    qs = qs & " WHERE <and other magic>;"

You don't need to give the table an alias but it just seems like the thing to do.


-Phil-





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use VBA to Read/Write a Access Query Gino Liu Access VBA 2 January 7th, 2012 04:03 AM
Passing Query from Access to MySAL using VBA stephej Access 3 June 20th, 2006 06:56 AM
Access VBA Delete Query Issue... snoopy92211 Access VBA 4 June 24th, 2004 03:57 PM
How to set (right click)properties for an object mpkrishna Classic ASP Components 1 August 24th, 2003 01:30 AM





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