sql query with parameters in a function

pitou

Registered User.
Local time
Today, 23:41
Joined
Aug 6, 2002
Messages
18
hello

I m trying to find the solution of a problem.
I wrote in a module this function :


-------------------

Function sql_action_ajout(ByVal NameTable As String, _
ByVal Namequery As String, ByVal ConditionWhere As String) As String

Dim SQL As String, SQLIns As String, SQLSel As String, _
SQLFrm As String, SQLWhr As String

SQLIns = "INSERT INTO [" & NameTable & "]"

SQLSel = "SELECT *"

SQLFrm = "FROM [" & Namequery & "]"

If ConditionWhere <> "" Then
SQLWhr = "WHERE " & ConditionWhere
Else
SQLWhr = ""
End If

End function()

--------------------------

In a form I created a click button with a small script related :


Dim dbs as database
Set dbs = currentdb()

dbs.Execute sql_action_ajout(table1, applicants, " " )


What I expected from this small script was to trigger (call) the sql query contained in the function "sql_action_ajout".

What I wanted to do is to put all the records from applicants into table1; nothing occured !
Moreover, a message appeared, saying that "table1", the first parameter, "was not a declared variable".

I thought we had only to fulfill the parameter one after another in order of appearance.

Am I wrong with the syntax ? perheaps I forgot something ?
Did I forget any quotations?
I hope my english is clear enough

Thanks, in advance for the forthcoming helpful ones.

Jean-Pierre
 
Test your function on it's own...

I can't see where you set the return value, i.e.

sql_action_ajout = ???
 
Thanks in advance for both of you to have helped me but my mastery of the English language is not strong enough.
What is an append query ?
I do not understand either the Ritchieroo's remark about to test
Test your function on it's own...

Well in fact, should it be possible to give a short example of a function with just ONE parameter ? a sql query E.G
delete * from & nametable1 &" with the name of the table to delete in parameter, and the few lines of code that correspond to the function by giving the name of the table

With this example I will be able to understand gradually by myself



Thanks a lot in advance


Jean-Pierre
 
Bonjour Jean-Pierre.

Have you found a solution on your problem?

Regards
Soren
 

Users who are viewing this thread

Back
Top Bottom