Hello all,
First off, the experts on this site have been so helpful in my VBA endeavours. I can't thank you enough. Now, my next challenge.....
I have been using the following code to pull data from various queries within my database....
Sub Get_Data ()
' pull data from the database
ActiveSheet.Name = "-Sheet1-"
Cells.Select
Selection.Delete Shift:=xlUp
Range("A1").Select
Dim dbs1 As DAO.Database
Dim rst1 As DAO.Recordset
Dim i1 As Long
Dim wsh1 As Worksheet
Set dbs1 = DBEngine.OpenDatabase("\\cherubim\RW Shares\MiniMRP DataMine\MiniMRP Data Mine.accdb") 'select the database
Set rst1 = dbs1.OpenRecordset("Ship List1") ' select the query
Set wsh1 = Worksheets("-Sheet1-")
For i = 0 To rst1.Fields.count - 1
wsh1.Cells(1, i + 1).Value = rst1.Fields(i).Name
Next
wsh1.Range("A1").Resize(ColumnSize:=rst1.Fields.count).Font.Bold = True
wsh1.Range("A2").CopyFromRecordset rst1
rst1.Close
Set rst1 = Nothing
dbs1.Close
Set dbs1 = Nothing
It has worked out great until today. I now need to pull data from a couple of queries in Access that have inputs that need to be filled in before the query runs. How could / would I modify the above code to allow me to have input boxes to satisfy the Access query when my macro is run in Excel?
First off, the experts on this site have been so helpful in my VBA endeavours. I can't thank you enough. Now, my next challenge.....
I have been using the following code to pull data from various queries within my database....
Sub Get_Data ()
' pull data from the database
ActiveSheet.Name = "-Sheet1-"
Cells.Select
Selection.Delete Shift:=xlUp
Range("A1").Select
Dim dbs1 As DAO.Database
Dim rst1 As DAO.Recordset
Dim i1 As Long
Dim wsh1 As Worksheet
Set dbs1 = DBEngine.OpenDatabase("\\cherubim\RW Shares\MiniMRP DataMine\MiniMRP Data Mine.accdb") 'select the database
Set rst1 = dbs1.OpenRecordset("Ship List1") ' select the query
Set wsh1 = Worksheets("-Sheet1-")
For i = 0 To rst1.Fields.count - 1
wsh1.Cells(1, i + 1).Value = rst1.Fields(i).Name
Next
wsh1.Range("A1").Resize(ColumnSize:=rst1.Fields.count).Font.Bold = True
wsh1.Range("A2").CopyFromRecordset rst1
rst1.Close
Set rst1 = Nothing
dbs1.Close
Set dbs1 = Nothing
It has worked out great until today. I now need to pull data from a couple of queries in Access that have inputs that need to be filled in before the query runs. How could / would I modify the above code to allow me to have input boxes to satisfy the Access query when my macro is run in Excel?