I am trying to get multiple usernames from a single text box, then to search a database to list all sections a username has access to, and then export that data to an Excel spreadsheet. A single spread sheet would be nice, but multiple spread sheets would be fine.
I have managed to get the data to an array, and have the code to export to an Excel spreadsheet, but my knowledge at the moment of vba doesn't go far enough to be able to link this together, so it uses the SQL statement to search through the tables to get the information of the access each user has and then somehow either store it and dump it to a single spread sheet, or just save it to a new spreadsheet each time is searches the database.
I have looked around but can't see how the ways I have seen can be translated into what I want. I guess you'd have to put the SQL results back into an Array and then do a dump to excel somehow?
I don't even know if this is possible to do in vba.
Code that I currently have, which I know won't work in it's current state:
Private Sub Command12_Click()
Dim strSQL As String
Dim strQry As String
Dim selecteduser As String
Dim db As DAO.Database
Dim Qdf As QueryDef
Users = Me.Text13
Dim usernames() As String
usernames() = Split(Users, ",")
strSQL = "SELECT tblPra.praNo, tblFolder.folder, tblFolder.fullTitle FROM "&_
"tblPra INNER JOIN (tblFolder INNER JOIN tblRelationship ON " &_
"tblFolder.folderID = tblRelationship.folderID) ON " &_
"tblPra.praID = tblRelationship.praID " &_
"WHERE (((tblPra.praNo)='" & usernames & "'));"
strQry = "tempuser"
Set db = CurrentDb
Set Qdf = db.CreateQueryDef(strQry, strSQL)
On Error Resume Next
DoCmd.DeleteObject acQuery, "strQry"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, _
strQry, "C:\Users\name\Desktop\test.xls", True
DoCmd.DeleteObject acQuery, strQry
End Sub
Any help, advice or point in the right direction would be greatly appreciated!