Make table query -> table name to be the parameter

hunoob

Registered User.
Local time
Today, 15:18
Joined
Feb 17, 2009
Messages
90
Hi Everyone! I have a make-table query with a parameter. I have a function which does the following:
1) ask for a new table name
2) start running the SQL query
3) the SQL query asks for a parameter
4) the new table is created with the new query data.

Here is the code:

Function CreateTable()
Dim NewTableName As String
NewTableName = InputBox("Please select new table name")
If Len(Trim(NewTableName)) <> 0 Then
DoCmd.RunSQL "PARAMETERS KockKod Text ( 255 ); SELECT [Kockazatok-proba].RiskID, [Kockazatok-proba].[Risk name], Nevek.Vezetéknév, Nevek.Keresztnév, Nevek.[Harmadik név], Nevek.[E-mail cím] INTO " & NewTableName & " FROM [Kockazatok-proba] INNER JOIN Nevek ON [Kockazatok-proba].Nevek.Value = Nevek.Vezetéknév WHERE ((([Kockazatok-proba].RiskID)=[KockKod]))"
End If
End Function


My problem is that the table name is the parameter, so is it possible to make the code to make a new table with the name of parameter, without prompting me for a new table name at the beginning.

Thank you in advance!
 
Last edited:
Does the code that you posted here fail somehow? Have you run it?
 
Does the code that you posted here fail somehow? Have you run it?


Hi Lagbolt! As I wrote in my post. The code is working properly. My problem is that I would like to simplify the code. Instead of manually typing in the name of the table, the code should automatically name the new table the SQL parameter.

Please someone help me! Thank you!
 
So assign the value of the parameter to the variable called 'NewTableName'?
Code:
NewTableName = Me.KockKod
Would that work for you?
Cheers,
 

Users who are viewing this thread

Back
Top Bottom