Hi everyone,
I have a sql query in my vba code.
My data connection uses ado.
The query result will be stored into my table.
Now I want to use a form in order to set the date range and a name filter where I can chose a name or if not all names will be selected, see attached screenshot.
Field 1 = start date, field 2 = end date and field 3 a list filter.
form.jpg
Let's say we have a sql query like:
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strCon As String
Sub VPA_Report()
Call fClearSheet(1)
strCon = "Driver={SQL Server Native Client 11.0}; Server=example;Database=test;User Id=a_user;Password=123456789;"
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
cn.Open strCon
strSQL = "select emp_last_name, emp_first_name, hire_date from employe order by 1 asc"
rs.Open strSQL, cn
'insert data into worksheet
Table.Range("A12:J12").CopyFromRecordset rs
MsgBox "query has been done"
rs.Close
cn.Close
end sub
I already created the form but how to use the bind variable to my sql code? And how call this form?
First the form has to be called that the user can insert a date or select a name.
Thanks for any advice or example.
Bookmarks