A
alex
Make table from recordset
Hello,
I’m attempting to make a table based of a union parameter query, all
in VBA…
I have this code which prints the results in the immediate window, but
I can’t figure out how to make a simple table with one column of
RecordNumbers (make table – deleted/made every time code executes):
--------------------------------------------------------------------------
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Dim strLName As String
strLName = InputBox("Last Name?")
Dim strFName As String
strFName = InputBox("First Name?")
Dim strDOB As String
strDOB = InputBox("DOB?")
strSQL = _
"SELECT tblTest.RecordNumber as RecordNumber" & _
" FROM tblTest " & _
" WHERE (tblTest.Last_Name) Like """ & strLName & """" & _
" AND (tblTest.First_Name) Like """ & strFName & """" & _
" AND (tblTest.Date_Of_Birth) Like """ & strDOB & """"
‘ the rest of union query here….
'Debug.Print strSQL
Set dbs = CurrentDb()
' Create recordset based on SQL
Set rst = dbs.OpenRecordset(strSQL)
Do While Not rst.EOF
'Debug.Print rst![RecordNumber]
rst.MoveNext
Loop
'make tbl here?
rst.Close
dbs.Close
Hello,
I’m attempting to make a table based of a union parameter query, all
in VBA…
I have this code which prints the results in the immediate window, but
I can’t figure out how to make a simple table with one column of
RecordNumbers (make table – deleted/made every time code executes):
--------------------------------------------------------------------------
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Dim strLName As String
strLName = InputBox("Last Name?")
Dim strFName As String
strFName = InputBox("First Name?")
Dim strDOB As String
strDOB = InputBox("DOB?")
strSQL = _
"SELECT tblTest.RecordNumber as RecordNumber" & _
" FROM tblTest " & _
" WHERE (tblTest.Last_Name) Like """ & strLName & """" & _
" AND (tblTest.First_Name) Like """ & strFName & """" & _
" AND (tblTest.Date_Of_Birth) Like """ & strDOB & """"
‘ the rest of union query here….
'Debug.Print strSQL
Set dbs = CurrentDb()
' Create recordset based on SQL
Set rst = dbs.OpenRecordset(strSQL)
Do While Not rst.EOF
'Debug.Print rst![RecordNumber]
rst.MoveNext
Loop
'make tbl here?
rst.Close
dbs.Close