如何使用VBA在Quickbooks中添加多行Expense项目?

问题描述 投票:0回答:1

到目前为止,我一直在使用此处找到的代码向QB添加新的检查:https://pulseinfomatics.com/quickbooks-sdk-iaddcheck-using-vba-add-a-check-from-excel-or-access/

我可以添加支票确认,但我需要在支票上添加多行费用项目。我已经尝试过这段代码,但它只使用代码中列出的最后一项(“第三项”)(代码仅用于测试如何执行此操作)。

smgr.OpenConnection "", "your appname"
smgr.BeginSession "", omDontCare
Dim qresp As IResponse
Dim rList As IResponseList
Dim chklist As ICheckRetList
Dim rMsg As IMsgSetRequest
Dim rMsgr As IMsgSetResponse
Dim iChk As ICheckAdd

Dim datChkDate As Date
Dim strCustRef As String

strCustRef = ""
datChkDate = Date

Set rMsg = smgr.CreateMsgSetRequest("US", 13, 0)

Set iChk = rMsg.AppendCheckAddRq()
iChk.TxnDate.SetValue (datChkDate)
iChk.AccountRef.FullName.SetValue (strBankAccount)
iChk.PayeeEntityRef.FullName.SetValue (strCustName)
iChk.Address.Addr1.SetValue (strStreet1)
iChk.Address.Addr2.SetValue (strStreet2)
iChk.Address.City.SetValue (strCity)
iChk.Address.State.SetValue (strState)
iChk.Address.PostalCode.SetValue (strZip)
iChk.Memo.SetValue (strMemo)
Dim iExp As IExpenseLineAdd
Set iExp = iChk.ExpenseLineAddList.Append()

iExp.Amount.SetValue (curAmount)
iExp.AccountRef.FullName.SetValue (strAccount)
iExp.Memo.SetValue ("first")

'iExp.CustomerRef.FullName.SetValue (strCustRef)

iExp.Amount.SetValue (curAmount)
iExp.AccountRef.FullName.SetValue (strAccount)
iExp.Memo.SetValue ("Second")

iExp.Amount.SetValue (curAmount)
iExp.AccountRef.FullName.SetValue (strAccount)
iExp.Memo.SetValue ("Third")

Set rMsgr = smgr.DoRequests(rMsg)
strResponse = rMsgr.ToXMLString()

QBAddCheck = strResponse

Set rMsg = Nothing
Set iChk = Nothing
Set iExp = Nothing
Set rMsgr = Nothing

smgr.EndSession
smgr.CloseConnection
Set smgr = Nothing

End Function

这是QB Pro 2017窗口的屏幕截图,显示了我要做的事情:

QB Pro 2017 write check screen

你怎么做到这一点?

谢谢,TD

vba ms-access quickbooks
1个回答
1
投票

虽然我自己没有这样做 - 我相信我在你的代码中看到了这个问题。如果您只获取最后一个值(在您的示例中为第三个值),那是因为您需要在每个值创建之前使用下面的代码。否则,设置该值只会重置该行的值,但不会添加新行。

此外,如果您期望超过3行 - 我建议使用循环遍历所有项目并添加确切的金额,而不是每次添加数字行。

Set iExp = iChk.ExpenseLineAddList.Append()
iExp.Amount.SetValue (curAmount)
iExp.AccountRef.FullName.SetValue (strAccount)
iExp.Memo.SetValue ("first")

Set iExp = iChk.ExpenseLineAddList.Append()
iExp.Amount.SetValue (curAmount)
iExp.AccountRef.FullName.SetValue (strAccount)
iExp.Memo.SetValue ("Second")

Set iExp = iChk.ExpenseLineAddList.Append()
iExp.Amount.SetValue (curAmount)
iExp.AccountRef.FullName.SetValue (strAccount)
iExp.Memo.SetValue ("Third")
© www.soinside.com 2019 - 2024. All rights reserved.