J
JT
Below is my constant and the code that uses it. This works great as it is.
Const ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Projects\MyDatabase.mdb;Persist Security Info=False"
Dim Recordset As ADODB.Recordset
Dim vSQL As String
vSQL = "select * from CurrentData where GP = '" & vGrp & "' AND BR = '" &
vBr & "'"
Set Recordset = New ADODB.Recordset
Call Recordset.Open(vSQL, connectionstring, adOpenForwardOnly,
adLockReadOnly, CommandTypeEnum.adCmdText)
Worksheets(vSheet1).Activate
Call ActiveSheet.Range("A5").CopyFromRecordset(Recordset)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
However, I would like to use a variable in the Source section of the
constant because the file name will change each week (instead of hardcoding a
file name and path).
I haven't used constants at all, so I'm not sure if this is possible. If
you can do this, what would the syntax be? Any suggestions or code to help
with this situation would be greatly appreciated. Thanks for all of the
help.......
Const ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Projects\MyDatabase.mdb;Persist Security Info=False"
Dim Recordset As ADODB.Recordset
Dim vSQL As String
vSQL = "select * from CurrentData where GP = '" & vGrp & "' AND BR = '" &
vBr & "'"
Set Recordset = New ADODB.Recordset
Call Recordset.Open(vSQL, connectionstring, adOpenForwardOnly,
adLockReadOnly, CommandTypeEnum.adCmdText)
Worksheets(vSheet1).Activate
Call ActiveSheet.Range("A5").CopyFromRecordset(Recordset)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
However, I would like to use a variable in the Source section of the
constant because the file name will change each week (instead of hardcoding a
file name and path).
I haven't used constants at all, so I'm not sure if this is possible. If
you can do this, what would the syntax be? Any suggestions or code to help
with this situation would be greatly appreciated. Thanks for all of the
help.......