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
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
You would need to concatenate the form control value with the sql string

Rich (BB code):
strSQL = "SELECT * FROM tblFilm in '" &  [forms]![form1]![txtPath]  & "'"


 
Upvote 0
thanks for your quick reply.


I need to put this in query ( ms Access query design view) how I can do that what part I have to remove?

strSQL = "SELECT * FROM tblFilm in '" & [forms]![form1]![txtPath] & "'"








 
Last edited:
Upvote 0
In the query property sheet you enter this as the Source Database:
[forms]![form1]![txtPath]

In my opinion just as easy to use SQL View, in which case use the query as described above:
strSQL = "SELECT * FROM tblFilm in '" & [forms]![form1]![txtPath] & "'"

If you do either one, you can see the result switching back and forth from SQL view and Design View.
 
Last edited:
Upvote 0
In the query property sheet you enter this as the Source Database:
[forms]![form1]![txtPath] --------------------------------I have tried but this not work.


I'm looking for SQL view only.

could you tell me what would be query in SQL view , I have tried many time but couldn't pass.


Thanks for reply.
 
Upvote 0
It is just as described above (although I do notice one missing double quote in the above posts, which is fixed below):
SELECT * FROM tblFilm in "'" & [forms]![form1]![txtPath] & "'"

This will only work if Form1 is open and has a valid path to an existing database with the expected table in it.
 
Last edited:
Upvote 0
apologies no it doesn't work with the Forms!Form!txtBox syntax - or rather the database accepts the syntax but fails at runtime.
 
Upvote 0
I doubt it. It's pretty straightforward so either it works or it doesn't

(well, of course you could just add tblFilms as a linked table in the database but I assume you have a reason you are not doing that already).
 
Last edited:
Upvote 0
thanks for reply.

I'm working on macro someone built in past not allowed to changed it.

I have strong feeling there is solution to incorporate form reference in this scenario, but don't know how to do it now:)

I will share if I get anything on this.


thanks again

Mukesh Y
 
Upvote 0

Forum statistics

Threads
1,214,387
Messages
6,119,222
Members
448,877
Latest member
gb24

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