S
Stephen Lynch
I am a novice here and I am trying to loop through a loop. My first loop
would be a groupof departments in a company, so I grouped a query on the
departments. I want to start with the first department and print each
employee in each department using that department as the parameter and print
the file and then move to the next department and print those employees and
so on. (This is really not what I am doing but it clarifies the example)
I keep getting a "no current record error" on myset.MoveFirst but I know
that there are records. It stops on the myset.MoveFirst highlighted below
with astericks.
Do I need to close a recordset first? Any help is appreciated. Thanks
****************************************************
Dim StrMasterID As String
Dim strMaster2Use As String
Dim strSQLMasterID As String
'go though each master so we can us the master as a parameter for the
loop below
strSQLMasterID = "SELECT tblSellSharesParticipant.MasterID From
tblSellSharesParticipant WHERE (((tblSellSharesParticipant.SellDecision) Not
Like 'Do Nothing'))GROUP BY tblSellSharesParticipant.MasterID ORDER BY
tblSellSharesParticipant.MasterID;"
Set db = CurrentDb()
Set rst = db.OpenRecordset(strSQLMasterID, dbOpenDynaset)
Do While Not rst.EOF
'***2nd loop using the parameter strSQL
strMaster2Use = rst![MasterID]
strSQL = "SELECT tblSellSharesParticipant.SchwabAccNo,
tblSellSharesParticipant.SellDecision, tblSellSharesParticipant.Symbol,
tblSellSharesParticipant.Shares, tblSellSharesParticipant.SecurityType,
tblSellSharesParticipant.MktValue, tblSellSharesParticipant.SharePrice,
tblSellSharesParticipant.SecDesc1,
tblSellSharesParticipant.SharesSubject2STRP,
tblSellSharesParticipant.SharesNotSubjectValue,
tblSellSharesParticipant.SellDollarAmount, tblSellSharesParticipant.MasterID
From tblSellSharesParticipant WHERE
(((tblSellSharesParticipant.SellDecision) Not Like 'Do Nothing') AND
((tblSellSharesParticipant.MasterID)= ' " & strMaster2Use & " ' ));"
Set mydb = CurrentDb()
Set myset = mydb.OpenRecordset(strSQL, dbOpenDynaset)
intFile = FreeFile
strMaster = strMaster2Use
Open "C:\" & strMaster & "\schwab.txt" For Output As intFile
LSet Header = "HD FA M " & strMaster & " FA30 M" & Right(strMaster,
7)
Print #intFile, Header
myset.MoveFirst *****HERE I AM ERRORING OUT WITH NO CURRENT
RECORD
Do While Not myset.EOF
If myset![SellDecision] = "Sell All Shares" Then
strPercentageSell = "1.00"
strSharestoSell = 0
strDollarAmttoSell = 0
Else
If myset![SellDecision] = "Sell Shares Not Subject" Then
strPercentageSell = 0
strDollarAmttoSell = 0
strSharestoSell = myset![Shares] - myset![SharesSubject2STRP]
strSharestoSell = Round(strSharestoSell, 4)
Else
If myset![SellDecision] = "Sell Dollar Amount" Then
strPercentageSell = 0
strDollarAmttoSell = myset![SellDollarAmount]
strSharestoSell = 0
If myset![SellDecision] = "Do Nothing" Then
End If
End If
End If
End If
RSet strA = "TR"
LSet strB = myset![AccNo]
RSet strD = "SELL SHRS"
RSet strE = IIf(strDollarAmttoSell = 0, "", strDollarAmttoSell)
RSet strF = IIf(strSharestoSell = 0, "", strSharestoSell)
RSet strH = IIf(strPercentageSell = 0, "", strPercentageSell)
RSet strJ = myset![Symbol]
RSet strL = "N"
RSet strP = "13051299"
RSet strR = "0"
'Concatenate all of the variables together as in the following:
Print #intFile, strA; strB; strC; strD; strE; strF; strG; strH;
strI; strJ; strK; strL; strM; strN; strO; strP; strQ; strR
myset.MoveNext
Loop
Close intFile
myset.Close
mydb.Close
MsgBox "File sent to C:\" & strMaster & "\schwab.txt", , "Trades
Generated for Import!"
rst.MoveNext
Loop
End Sub
would be a groupof departments in a company, so I grouped a query on the
departments. I want to start with the first department and print each
employee in each department using that department as the parameter and print
the file and then move to the next department and print those employees and
so on. (This is really not what I am doing but it clarifies the example)
I keep getting a "no current record error" on myset.MoveFirst but I know
that there are records. It stops on the myset.MoveFirst highlighted below
with astericks.
Do I need to close a recordset first? Any help is appreciated. Thanks
****************************************************
Dim StrMasterID As String
Dim strMaster2Use As String
Dim strSQLMasterID As String
'go though each master so we can us the master as a parameter for the
loop below
strSQLMasterID = "SELECT tblSellSharesParticipant.MasterID From
tblSellSharesParticipant WHERE (((tblSellSharesParticipant.SellDecision) Not
Like 'Do Nothing'))GROUP BY tblSellSharesParticipant.MasterID ORDER BY
tblSellSharesParticipant.MasterID;"
Set db = CurrentDb()
Set rst = db.OpenRecordset(strSQLMasterID, dbOpenDynaset)
Do While Not rst.EOF
'***2nd loop using the parameter strSQL
strMaster2Use = rst![MasterID]
strSQL = "SELECT tblSellSharesParticipant.SchwabAccNo,
tblSellSharesParticipant.SellDecision, tblSellSharesParticipant.Symbol,
tblSellSharesParticipant.Shares, tblSellSharesParticipant.SecurityType,
tblSellSharesParticipant.MktValue, tblSellSharesParticipant.SharePrice,
tblSellSharesParticipant.SecDesc1,
tblSellSharesParticipant.SharesSubject2STRP,
tblSellSharesParticipant.SharesNotSubjectValue,
tblSellSharesParticipant.SellDollarAmount, tblSellSharesParticipant.MasterID
From tblSellSharesParticipant WHERE
(((tblSellSharesParticipant.SellDecision) Not Like 'Do Nothing') AND
((tblSellSharesParticipant.MasterID)= ' " & strMaster2Use & " ' ));"
Set mydb = CurrentDb()
Set myset = mydb.OpenRecordset(strSQL, dbOpenDynaset)
intFile = FreeFile
strMaster = strMaster2Use
Open "C:\" & strMaster & "\schwab.txt" For Output As intFile
LSet Header = "HD FA M " & strMaster & " FA30 M" & Right(strMaster,
7)
Print #intFile, Header
myset.MoveFirst *****HERE I AM ERRORING OUT WITH NO CURRENT
RECORD
Do While Not myset.EOF
If myset![SellDecision] = "Sell All Shares" Then
strPercentageSell = "1.00"
strSharestoSell = 0
strDollarAmttoSell = 0
Else
If myset![SellDecision] = "Sell Shares Not Subject" Then
strPercentageSell = 0
strDollarAmttoSell = 0
strSharestoSell = myset![Shares] - myset![SharesSubject2STRP]
strSharestoSell = Round(strSharestoSell, 4)
Else
If myset![SellDecision] = "Sell Dollar Amount" Then
strPercentageSell = 0
strDollarAmttoSell = myset![SellDollarAmount]
strSharestoSell = 0
If myset![SellDecision] = "Do Nothing" Then
End If
End If
End If
End If
RSet strA = "TR"
LSet strB = myset![AccNo]
RSet strD = "SELL SHRS"
RSet strE = IIf(strDollarAmttoSell = 0, "", strDollarAmttoSell)
RSet strF = IIf(strSharestoSell = 0, "", strSharestoSell)
RSet strH = IIf(strPercentageSell = 0, "", strPercentageSell)
RSet strJ = myset![Symbol]
RSet strL = "N"
RSet strP = "13051299"
RSet strR = "0"
'Concatenate all of the variables together as in the following:
Print #intFile, strA; strB; strC; strD; strE; strF; strG; strH;
strI; strJ; strK; strL; strM; strN; strO; strP; strQ; strR
myset.MoveNext
Loop
Close intFile
myset.Close
mydb.Close
MsgBox "File sent to C:\" & strMaster & "\schwab.txt", , "Trades
Generated for Import!"
rst.MoveNext
Loop
End Sub