Reputation: 1
I need some help with passing a parameter to a MySQL database table query. I have multiple unique tables which I need to query depending on the "client*" parameter.
In order to avoid writing endless if statements, I need a way to pass each unique client parameter .i.e "client1_" to the database query below. So instead of hard coding the "client1_accounts" etc in the query below each time, I need a way to be able to just attach the "client*" parameter to sections of the query where required and avoid writing an if statement as the parameter for each instance will be declared.
If tablePrefix = "client1_" Then
Set myconn = New ADODB.Connection
Set rs_client1_accounts = New ADODB.Recordset
myconn.Open "Driver={MySQL ODBC 3.51 Driver};server=" & frmSettings.Text1(0).Text & ";uid=" & frmSettings.Text1(2).Text & ";pwd=" & frmSettings.Text1(3).Text & ";database=" & frmSettings.Text1(1).Text & ""
mysql = "SELECT * FROM client1_accounts"
rs_client1_accounts.Open mysql, myconn, adOpenKeyset, adLockPessimistic
Do Until rs_client1_accounts.EOF = True
List1.AddItem rs_client1_accounts!account
rs_client1_accounts.MoveNext
Loop
ElseIf tablePrefix = "client2_ Then
.... etc ... etc
End if
I hope I've explained properly what I want to do but if I haven't please ask any question and I'll do my best to clarify.
Thanks for your help!
Upvotes: 0
Views: 119
Reputation: 13008
Instead of
mysql = "SELECT * FROM client1_accounts"
use
mysql = "SELECT * FROM " & tablePrefix & "accounts"
The result of the second example is a string concatenation identical to the string in the first example.
Upvotes: 1