Form reference in MS Access query

MUKESHY12390

Well-known Member
Joined
Sep 18, 2012
Messages
901
Office Version
  1. 2013
  2. 2011
  3. 2010
  4. 2007
Platform
  1. Windows
Hi All,

I'm trying to build query by using form reference but it's not working.

Can anyone point me toward right direction.

PHP:
SELECT *FROM tblFilm in [forms]![form1]![txtPath]


'------ this below one works perfectly -------



PHP:
SELECT *FROM tblFilm in 'D:\Training stuff\BU\2copy.mdb'



Any help would be appreciated.

Thanks
Mukesh Y
 
This appears to work:

SELECT *
FROM tblFilm IN 'Database2.accdb'[[Forms].Form1.txtPath];

Design-wise it corresponds to having Database2.accdb in the Source Database property, and [Forms].Form1.txtPath in the Source Connect Str property. Having a play with it seems to show that the connect str can have the folder path or full file path, works either way. But the source database property needs the Database name.

Although this doesn't look clean since you would need two textboxes really - one for the path, one for the database name. Unless some kind of string parsing comes to the rescue (or other combination works that is not yet discovered by one of use).
 
Upvote 0

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
I'm glad you came with another solution,but my situation doesn't allow me to use,

Thanks
Mukesh Y
 
Upvote 0
I believe you are confusing VBA and SQL syntax?

I used the builder to create the SQL below which works.
Code:
SELECT [old Transactions].*, [old Transactions].Category
FROM [old Transactions]
WHERE ((([old Transactions].Category) In ([Forms]![Form1]![txtCriteria])));

Do not include strSQL=
That is to build a string to execute from VBA
However
Code:
strSQL="SELECT [old Transactions].*, [old Transactions].Category FROM [old Transactions] WHERE ((([old Transactions].Category) In ([Forms]![Form1]![txtCriteria])));" should still work
Old Transactions is just a table I used to test. As mentioned form has to be open for this to work.?
HTH
 
Last edited:
Upvote 0
SELECT [old Transactions].*, [old Transactions].Category
FROM [old Transactions]
WHERE ((([old Transactions].Category) In ([Forms]![Form1]![txtCriteria])));

I'm creating select query for another database (MS Access) which saved in shared drive, in above query you have used table which already exist in database.

could you tell me how to give path reference in above query.

this is syntax :

Code:
SELECT * FROM MyTable IN "C:\Test.mdb"





I
 
Upvote 0
I think the nub here is what to put in the form field (i.e., what is the value we are reading in [Forms]![Form1]![txtCriteria]).
I don't know the answer. I believe that what Mukeshy would *like* to enter is the full path to the remote database (C:\somefolder\somedatabase.accdb). Also I gather that we are limited by note being able to use VBA, but having to use/edit an MSAccess macro instead (which is not my strong suit).

Edit:
note that for clarity to readers of the post, we are talking about an MSAccess remote query, such as:
Code:
SELECT [Orders Qry].* FROM [Orders Qry] IN 'C:\msoffice97\Office\Samples\Northwind.mdb';
Description of Remote queries here: http://www.vb123.com.au/200108_gr_remote.htm
 
Last edited:
Upvote 0
Ok, never done anything like this before, so was intrigued to say the least. Also learnt something.

This worked for me
Code:
strSQL = "SELECT * from tblclient in '" & [Forms]![frmTable1]![txtData] & "'"

The form had
F:\Users\Paul\Documents\Commissions.accdb

in the data field

However that is VBA which we are now saying cannot be used.?

All I can think of is to create the sql for the query, save it in the qdf of that query (or make a copy and delete?) and then run the query from the macro?
 
Upvote 0
I believe you have mistaken.

Code:
This is vba code work perfectly.
strSQL = "SELECT * from tblclient in '" & [Forms]![frmTable1]![txtData] & "'"


what I'm trying : build a MS Access query where I can replace "C:\Test.mdb" with form reference like

"SELECT * from tblclient in '" & [Forms]![frmTable1]![txtData] & "'"

above line is not working in ms query.
 
Upvote 0
I'm pretty the "working" version employed VBA - so we can't use VBA. I imagine reconstructing the SQL query def and saving also envisions VBA so that's probably off the table too. I'm not very good with macros so not really sure (basically I've never used msaccess macros except in a handful of cases).
 
Last edited:
Upvote 0
Got me stumped.:oops:
Whatever you put for IN it takes literally?
I even tried Tempvars and it did the same thing.?

I think the o/p is going to have to rethink how it will all work.?

Easily doable with VBA, so why cripple yourself using macroes?
 
Upvote 0
Well for what its worth MSAccess macros have a different security context so I can imagine that as being one reason for using them. But that's speculation. It's possible in some workplaces you can't even use VBA - though I'd probably go nuts in such a place. Probably as a useful exercise it would be great to build a good, working, and properly functional database using no vba - just to discover and implement all the great builtin features of Access. But who has time for useful exercises :(
 
Upvote 0

Forum statistics

Threads
1,214,627
Messages
6,120,610
Members
448,973
Latest member
ChristineC

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top