Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parameters in query, when the parameter is a table name

Status
Not open for further replies.

halx

Programmer
Jun 5, 2002
35
FR
Hello !

getParameter(x) is a function that gives a table's name.
I want to write a query like:

SELECT *
FROM getParameter(1)

but it does not work.

Could anybody help me ?
thanks

Alex

 
What are you trying to do in the query with the table's name? "Get it right the first time, that's the main thing..." [wavey]
 
I want to select all the fields of the table whose name is given by the function getParameter(1).

But maybe it is not possible to pass the name of a table as parameter.

Alex
 
How are you capturing the parameter? In a form?
Jim "Get it right the first time, that's the main thing..." [wavey]
 
Yes, I should have precised it:
I have a module that contains an array (of parameters), a function to set this array and one to get the parameters.

Before I need the query, I set the parameters.
In the query, I call the parameter that I need (here, it is: getParameter(1))

It seems messy, but actually it makes many things easier ( for example, if I had taken the parameter from a form, I would have had problems if the form's name changes). I learnt about this method in this forum.

Alex
 
Can you please paste in the related parts from your module, and the layout of your table? I'd like to play with this.

Jim "Get it right the first time, that's the main thing..." [wavey]
 
Here it is:
-------------------------------------------------
Dim testCycleParameters(4)

Public Sub SetTestCycleParameters(ByVal InputVal, ByVal ParamID)
testCycleParameters(ParamID) = InputVal
End Sub

Public Function GetTestCycleParameters(ByVal ParamID)
GetTestCycleParameters = testCycleParameters(ParamID)
End Function
-------------------------------------------------

Alex
 
A real doozy! You said you learned about this method on this forum. Do you recall who answered your post or who wrote the post you found? He/she would be the best resource on this one.

It's beyond me!

Sorry! Jim "Get it right the first time, that's the main thing..." [wavey]
 
Try something like this:
dim str as string, strSQL as string

GetParameter(1) = str
strSQL = "SELECT * FROM " & str

currentdb.execute(strSQL) '(Or whatever you need to do with strSQL)

 
Oops, code in prior message:
dim str as string, strSQL as string

GetParameter(1) = str
strSQL = "SELECT * FROM " & str
currentdb.execute(strSQL)

SHOULD BE:

str=GetParameter(1)
strSQL = "SELECT * FROM " & str
currentdb.execute(strSQL)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top