PC Review


Reply
Thread Tools Rate Thread

Can a variable value from a form be used to query tables?

 
 
=?Utf-8?B?VHlib3I=?=
Guest
Posts: n/a
 
      9th Dec 2006
I would like to set up a utility that I could run the same code on different
tables by changing the value of an unbound text from a form to the code. In
the following code what could I put in for [any table] that would allow this?
Or is there another way?

Sub any_Table()
Dim db As Database
Dim rsProvider As DAO.Recordset

Dim strSQL As String
Dim iPos, iLen As Integer

Set db = CurrentDb

strSQL = "Select * from [Any table]"
Set rsProvider = db.OpenRecordset(strSQL, dbOpenDynaset)

blah blah
end sub

Thanks
--
XTybor
 
Reply With Quote
 
 
 
 
Douglas J. Steele
Guest
Posts: n/a
 
      9th Dec 2006


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"Tybor" <(E-Mail Removed)> wrote in message
news:2A5B1994-BD86-429D-963E-(E-Mail Removed)...
>I would like to set up a utility that I could run the same code on
>different
> tables by changing the value of an unbound text from a form to the code.
> In
> the following code what could I put in for [any table] that would allow
> this?
> Or is there another way?
>
> Sub any_Table()
> Dim db As Database
> Dim rsProvider As DAO.Recordset
>
> Dim strSQL As String
> Dim iPos, iLen As Integer
>
> Set db = CurrentDb
>
> strSQL = "Select * from [Any table]"
> Set rsProvider = db.OpenRecordset(strSQL, dbOpenDynaset)
>
> blah blah
> end sub
>
> Thanks
> --
> XTybor



 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      9th Dec 2006
I'm not quite sure what you're asking.

Are you saying that have a text box on your form, and you want to be able to
put the name of the table there?

If the text box is named, say, txtTableName, you'd use:

strSQL = "Select * from [" & Me.txtTableName & "]"

(The reason for leaving the square brackets there is just in case any of
your table names include blanks, which I wouldn't recommend by the way).

In fact, you could use a combo box that returned the names of the tables,
and save your users having to type. The following query will return all your
table names, so could be used as a Row Source for the combo box:



--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"Tybor" <(E-Mail Removed)> wrote in message
news:2A5B1994-BD86-429D-963E-(E-Mail Removed)...
>I would like to set up a utility that I could run the same code on
>different
> tables by changing the value of an unbound text from a form to the code.
> In
> the following code what could I put in for [any table] that would allow
> this?
> Or is there another way?
>
> Sub any_Table()
> Dim db As Database
> Dim rsProvider As DAO.Recordset
>
> Dim strSQL As String
> Dim iPos, iLen As Integer
>
> Set db = CurrentDb
>
> strSQL = "Select * from [Any table]"
> Set rsProvider = db.OpenRecordset(strSQL, dbOpenDynaset)
>
> blah blah
> end sub
>
> Thanks
> --
> XTybor



 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      9th Dec 2006
Apologies: these responses are getting sent before I'm finished!

The following query could provide the Row Source for your combo box:

SELECT [Name]
FROM MSysObjects
WHERE [Type] IN (1, 4, 6)
AND [Name] NOT LIKE "MSys*"
ORDER BY [Name]

If you're asking for something else, post back with more details (and an
example, if possible)

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"Tybor" <(E-Mail Removed)> wrote in message
news:2A5B1994-BD86-429D-963E-(E-Mail Removed)...
>I would like to set up a utility that I could run the same code on
>different
> tables by changing the value of an unbound text from a form to the code.
> In
> the following code what could I put in for [any table] that would allow
> this?
> Or is there another way?
>
> Sub any_Table()
> Dim db As Database
> Dim rsProvider As DAO.Recordset
>
> Dim strSQL As String
> Dim iPos, iLen As Integer
>
> Set db = CurrentDb
>
> strSQL = "Select * from [Any table]"
> Set rsProvider = db.OpenRecordset(strSQL, dbOpenDynaset)
>
> blah blah
> end sub
>
> Thanks
> --
> XTybor



 
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
Pass variable from form to Query ... =?Utf-8?B?TWU=?= Microsoft Access Form Coding 6 10th Aug 2006 05:36 PM
Form variable in query Tezza Microsoft Access Queries 14 20th Jul 2006 11:03 PM
Re: Can I update tables from a form using query with multiple tables? John Vinson Microsoft Access 0 8th Sep 2004 11:45 PM
getting variable from query into form Globalnet_renato Microsoft Access Form Coding 1 4th Jun 2004 12:09 AM
How use form variable in a query ? martin Microsoft Access Queries 0 7th Oct 2003 06:56 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:27 PM.