M
Matt Williamson
I wrote some code to loop through a recordset and create an output file from
the data returned from a query. This works fine if I hard code the
parameters in the query, but I need a way to prompt for the input
parameters. I'm not sure how to do it. Given the following code, I'd like to
ask for user input for the portcode parameter. What are the options for
doing this? I haven't created a form to use a textbox. Can I just use
InputBox? If so, how would I code it?
Sub CreateBlotter()
Dim dbD As DAO.Database
Dim rsR As DAO.Recordset
Dim t As String, t2 As String
Dim sLine As String, sPath As String
Dim sSymbol As String, sBlotter As String
Dim prm As Parameter, qdf As QueryDef
t = ","
t2 = ",,"
sPath = GetPath(CurrentDb.Name)
sBlotter = sPath & "TaxLots.trn"
If bFileExists(sBlotter) Then Kill sBlotter
'Initialise
Set dbD = CurrentDb()
Set rsR = dbD.OpenRecordset("DataForExportFile", dbOpenSnapshot)
With rsR
Do While Not .EOF
If .Fields("sec type") > 4 Then
sSymbol = .Fields("cusip")
Else
sSymbol = .Fields("Primary Symbol")
End If
sLine = .Fields("portcode") & t & "li" & t2 & .Fields("sectype") & t &
sSymbol & t & _
FixDate(.Fields("settle Date")) & t2 & FixDate(.Fields("Trade
date")) & t & .Fields("Qty") & String(9, t) & .Fields("MktValue") & t & _
.Fields("OrigCost") & String(10, t) & "n" & t & "65533" &
String(12, t) & "1" & t2 & t & "n" & t & "y" & String(13, t) & "y"
WriteFile sBlotter, sLine
.MoveNext
Loop
.Close
End With
Set rsR = Nothing
Set dbD = Nothing
MsgBox "The file " & sBlotter & " has been created. "
End Sub
TIA
Matt
the data returned from a query. This works fine if I hard code the
parameters in the query, but I need a way to prompt for the input
parameters. I'm not sure how to do it. Given the following code, I'd like to
ask for user input for the portcode parameter. What are the options for
doing this? I haven't created a form to use a textbox. Can I just use
InputBox? If so, how would I code it?
Sub CreateBlotter()
Dim dbD As DAO.Database
Dim rsR As DAO.Recordset
Dim t As String, t2 As String
Dim sLine As String, sPath As String
Dim sSymbol As String, sBlotter As String
Dim prm As Parameter, qdf As QueryDef
t = ","
t2 = ",,"
sPath = GetPath(CurrentDb.Name)
sBlotter = sPath & "TaxLots.trn"
If bFileExists(sBlotter) Then Kill sBlotter
'Initialise
Set dbD = CurrentDb()
Set rsR = dbD.OpenRecordset("DataForExportFile", dbOpenSnapshot)
With rsR
Do While Not .EOF
If .Fields("sec type") > 4 Then
sSymbol = .Fields("cusip")
Else
sSymbol = .Fields("Primary Symbol")
End If
sLine = .Fields("portcode") & t & "li" & t2 & .Fields("sectype") & t &
sSymbol & t & _
FixDate(.Fields("settle Date")) & t2 & FixDate(.Fields("Trade
date")) & t & .Fields("Qty") & String(9, t) & .Fields("MktValue") & t & _
.Fields("OrigCost") & String(10, t) & "n" & t & "65533" &
String(12, t) & "1" & t2 & t & "n" & t & "y" & String(13, t) & "y"
WriteFile sBlotter, sLine
.MoveNext
Loop
.Close
End With
Set rsR = Nothing
Set dbD = Nothing
MsgBox "The file " & sBlotter & " has been created. "
End Sub
TIA
Matt