All,
I am having difficult with some code that is making use of a query that has a parameter in it. I have read the discussions here and think that I have made use of the suggestions to overcome the error. However, even with the code in place I am getting a popup box prompting me to enter the value of the parameter every time I run the code. Please help!
VBA Code:
Here is the SQL version of my Query ( I made it in design view - not in SQL clearly):
I am having difficult with some code that is making use of a query that has a parameter in it. I have read the discussions here and think that I have made use of the suggestions to overcome the error. However, even with the code in place I am getting a popup box prompting me to enter the value of the parameter every time I run the code. Please help!
VBA Code:
Code:
Private Sub cmdBonds_Click()
Forms![frmExistingAssets]![Label1].Caption = ""
Forms![frmExistingAssets]![Label2].Caption = ""
Forms![frmExistingAssets]![Label3].Caption = ""
Forms![frmExistingAssets]![Label4].Caption = ""
Forms![frmExistingAssets]![Label1].Caption = "Creating all Bond files..."
DoCmd.SetWarnings False
DoCmd.Hourglass True
outpath = get_ExportPath
Dim rst As DAO.Recordset
Dim rec As DAO.Recordset
Dim qd As DAO.QueryDef
Dim PortName As String
Dim PortName1 As String
Dim QryNameBND As String
Dim Filename As String
Dim stAppName As String
Application.Echo False
Set rst = CurrentDb.OpenRecordset("tblPortfolioNames")
Do Until rst.EOF
PortName = rst!CAMRAPortfolioName
PortName1 = rst!ProphetPortfolioName
Me.txtPortfolio = PortName
QryNameBND = "qryProphetBonds_AB"
Filename = outpath & "AB_" & PortName1 & ".txt"
[B]
Set qd = CurrentDb.QueryDefs(QryNameBND)
qd.Parameters![Name of Portfolio] = PortName [/b]
Set rec = qd.OpenRecordset
If rec.RecordCount < 1 Then
GoTo Next_Record
Else
DoCmd.TransferText acExportDelim, "AB BONDS RPT", QryNameBND, Filename, True
End If
Next_Record:
rst.MoveNext
Loop
Set rst = Nothing
Set rec = Nothing
Set qd = Nothing
stAppName = outpath & "RPT.BAT"
Call Shell(stAppName, vbMaximizedFocus)
Wait 6000
Application.Echo True
Forms![frmExistingAssets]![Label1].Caption = "Bond files done!"
DoCmd.SetWarnings True
DoCmd.Hourglass False
End Sub
Here is the SQL version of my Query ( I made it in design view - not in SQL clearly):
Code:
SELECT "*" AS [$], 1 AS SPCODE, Left(Recon_D1.cusip,3) AS CUSIP_1, Mid(Recon_D1.cusip,4,3) AS CUSIP_2, Right(Recon_D1.cusip,3) AS CUSIP_3, tblProphetBondRatings.Bond_Rating, 1 AS INIT_AS_GRP, RECON_D1.COUPON_RATE AS INCOME_PC, IIf([INT_DIV_FREQ]="ANNUAL",1,IIf([INT_DIV_FREQ]="MONTHLY",12,IIf([INT_DIV_FREQ]="QUARTRLY",4,2))) AS INCOME_FREQ, Year([Maturity_Date]) AS MAX_RED_YEAR, Month([Maturity_Date]) AS RED_MONTH, Day([Maturity_Date]) AS RED_DAY, Sum(RECON_D1.MARKETVALUE) AS INIT_MV, 1 AS INIT_MV_CLEAN, 1 AS INIT_MV_USED, 0 AS INIT_XYLD_PC, Sum(RECON_D1.BOOKVALUE) AS INIT_BV, 1 AS INIT_BV_CLN, Sum(RECON_D1.QUANTITY) AS INIT_NV, 3 AS ABV_METHOD, IIf([atrib_type]="CALLS",1,IIf([atrib_type]="PUTS",2,0)) AS BOND_TYPE, IIf([BOND_TYPE]=1,Year([FirstCallDate]),IIf([BOND_TYPE]=2,Year([FirstPutDate]),0)) AS MIN_RED_YEAR, IIf([BOND_TYPE]=1,Month([FirstCallDate]),IIf([BOND_TYPE]=2,Month([FirstPutDate]),0)) AS MIN_RED_MONTH, IIf([BOND_TYPE]=0,0,2) AS CALL_TYPE, 0 AS CALL_PERIOD, 0 AS AMO_TERM_IND, IIf([BOND_TYPE]=0,0,2) AS CALL_PRM_TYP
FROM (((RECON_D1 LEFT JOIN tblProphetBondRatings ON (RECON_D1.ACTUAL_MOODY = tblProphetBondRatings.MoodyRating) AND (RECON_D1.sec_group = tblProphetBondRatings.SecGroup)) LEFT JOIN SECATTRI ON RECON_D1.cusip = SECATTRI.cusip) LEFT JOIN qryFirstCallDate ON RECON_D1.cusip = qryFirstCallDate.cusip) LEFT JOIN qryFirstPutDate ON RECON_D1.cusip = qryFirstPutDate.cusip
WHERE (((RECON_D1.portfolio)=[Name of Portfolio]))
GROUP BY "*", 1, Left(Recon_D1.cusip,3), Mid(Recon_D1.cusip,4,3), Right(Recon_D1.cusip,3), tblProphetBondRatings.Bond_Rating, 1, RECON_D1.COUPON_RATE, IIf([INT_DIV_FREQ]="ANNUAL",1,IIf([INT_DIV_FREQ]="MONTHLY",12,IIf([INT_DIV_FREQ]="QUARTRLY",4,2))), Year([Maturity_Date]), Month([Maturity_Date]), Day([Maturity_Date]), 1, 1, 0, 1, 3, IIf([atrib_type]="CALLS",1,IIf([atrib_type]="PUTS",2,0)), 0, 0, RECON_D1.sec_group, qryFirstPutDate.FirstPutDate, qryFirstCallDate.FirstCallDate
HAVING (((RECON_D1.sec_group)="BONDS" Or (RECON_D1.sec_group)="SHORT TERM"));