We help IT Professionals succeed at work.

Access VBA Runtime Error 3021 No Current Record

Marilync1266
Marilync1266 asked
on
9,387 Views
Last Modified: 2013-11-27
HELP!  I'm about to demonstrate my application to some people and all of the sudden its not working.
In the afterUpdate event, I'm selecting item_total from a table and everytime I run this event, I get an error
Runtime Error 3021 no current record.  But I check my table and the data is there and the item no/quote no in the where statement match what is in my table.  What could I be doing wrong?

Dim DB As DAO.Database
Dim rstSum As DAO.Recordset
Dim strSQL As String
Dim intTotal As Double
Dim strPriceDescription As String
Dim intOldItemTotal As Currency
Dim intNewItemTotal As Currency
Dim intGrandTotal As Currency
Dim intTradeIn As Double
Dim intDiscounts As Double
Dim intTraining As Double
Dim intOther As Double
Dim strQuoteNo As String

If Nz(Me.Item_No) = "" Then
    GoTo Exit_Price_AfterUpdate
End If

intOldItemTotal = 0
intNewItemTotal = 0
intGrandTotal = 0
intTradeIn = 0
intDiscounts = 0
intTraining = 0
intOther = 0

Set DB = CurrentDb()

'Get Item Total Before Price Change
strSQL = "SELECT Item_Total FROM tbl_Quote_Equipment " & _
         "WHERE QuoteNo = '" & strQuoteNo & "' and Item_No = '" & Me.Item_No & "';"
Set rstSum = DB.OpenRecordset(strSQL, dbOpenDynaset)

intTradeIn = Forms!frm_Opportunity_Quote.Trade_In_Amount
intDiscounts = Forms!frm_Opportunity_Quote.Discounts_Amt
intTraining = Forms!frm_Opportunity_Quote.Training_Amt
intOther = Forms!frm_Opportunity_Quote.Other_Amt
strQuoteNo = Forms!frm_Opportunity_Quote.txtQuoteNo
intOldItemTotal = rstSum!Item_Total
Comment
Watch Question

CERTIFIED EXPERT

Commented:
'In the afterUpdate event'
of what? the form? a control?

And which line is highlighted when you get the error?
Eric ShermanAccountant/Developer
CERTIFIED EXPERT

Commented:
If Item_No is Numeric then ... use this.  I assume quote no is a string field.

"WHERE QuoteNo = '" & strQuoteNo & "' and Item_No = " & Me.Item_No & ";"


ET

CERTIFIED EXPERT
Top Expert 2016
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Item No is a string field too.
This is an form event
The row highlighted is:  intOldItemTotal = rstSum!Item_Total

Author

Commented:
There should be data in the recordset - I double checked the table and the criteria.  That is what baffles me.
CERTIFIED EXPERT
Top Expert 2016

Commented:
Marilync1266,
add the codes to test for  EOF and test. it will not lie to you

check  the data thoroughly
CERTIFIED EXPERT

Commented:
Set rstSum = DB.OpenRecordset(strSQL, dbOpenDynaset)
if rs.eof and rs.bof then
msgbox "No records"
exit sub
end if

intTradeIn = Forms!frm_Opportunity_Quote.Trade_In_Amount
intDiscounts = Forms!frm_Opportunity_Quote.Discounts_Amt

Author

Commented:
capricorn1:
You were so right - there was an error in my code.  Thanks for your help!
Eric ShermanAccountant/Developer
CERTIFIED EXPERT

Commented:
Try this just to see what it returns.

intOldItemTotal = DLookup("[Item_Total]", "tbl_Quote_Equipment", "[QuoteNo]= '" & strQuoteNo & '" AND [Item_No] = '" & Me.Item_No & '";")

ET



Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.