Results 1 to 6 of 6
  1. #1
    crazytrain is offline Novice
    Windows 11 Office 365
    Join Date
    Jan 2024
    Posts
    3

    Dropdown command causes Error 3021 No current record

    Novice struggling to troubleshoot some code and looking for help. I have a form "Remake Form" and in the BeforeUpdate Event I have code to validate if a combo box is empty. It worked until I tried to add code to dropdown the combo box.

    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    
    If Len(Me.PlantLocationBox & vbNullString) = 0 Then
            MsgBox "Please enter the missing info"
            Cancel = True
                Me.CustomerNameButton.SetFocus
                Me.PlantLocationBox.SetFocus
                Me.PlantLocationBox.Dropdown
            Exit Sub
        End If
    End Sub


    So if the
    PlantLocationBox is blank when I try to close the form, the message box pops up. I click OK and the command moves the focus to a field above the combo box (is this the correct way to get to the top of the form?). I then set the focus to the PlantLocationBox combo box. That works great, but if I add code to dropdown I get error 3021: No current record.

    What am I doing wrong? What's interesting to me is if I OK the error, and just try to save again, the message box validation pops up again. If I click OK a second time, the command works correctly, and the dropdown opens.

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Do not know the reason, but no need to set focus to another control first.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    crazytrain is offline Novice
    Windows 11 Office 365
    Join Date
    Jan 2024
    Posts
    3
    Quote Originally Posted by Welshgasman View Post
    Do not know the reason, but no need to set focus to another control first.
    If I don't set it to a control at the top of the page first, then then the screen just goes to the combo box. I wanted the form scroll all the way to the top. This was the only way I could figure out to get it close to the top so the user sees the whole top of the form and not just the top of the combo box.

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Hard to troubleshoot interactions with out seeing them. I suggest that you copy db, compact it, zip it and post here. You can remove objects if they're not relevant (just make sure you can replicate the problem in the copy db first). Let us know what user actions to take to replicate the problem.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    crazytrain is offline Novice
    Windows 11 Office 365
    Join Date
    Jan 2024
    Posts
    3
    Quote Originally Posted by Micron View Post
    Hard to troubleshoot interactions with out seeing them. I suggest that you copy db, compact it, zip it and post here. You can remove objects if they're not relevant (just make sure you can replicate the problem in the copy db first). Let us know what user actions to take to replicate the problem.
    AFtestCopy.zip

    Open the Remake Form and change or type something into any field EXCEPT Plant Location. Go to the bottom of the form and click the Save & Close Button. Answer Yes to save the changes. The message box will pop up. Click OK. Then the error will pop up.

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    If I change a field value, you should not allow the form to be closed rather than deleting my changes because of one missing field:
    Cancel = True
    Because you have that, the record being edited is no longer current, and no record takes its place - nor would you want it to. Comment out that line as shown and the error should not be raised.
    MsgBox "Location cannot be empty. Please enter before exit."
    'Cancel = True

    You will need to either
    - cancel all the editing (so don't use Me.Dirty = False) and close the form without saving changes, or
    - don't allow user to close the form until required fields are filled in (or if they insist, dump the record or its changes)

    Also, your combo gotfocus event will undo the dropdown.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 04-10-2020, 11:18 AM
  2. Runime Error '3021': - No current record
    By Mohanss82 in forum Programming
    Replies: 2
    Last Post: 07-04-2016, 02:34 AM
  3. sql error . runtime 3021 - no current record
    By princess12 in forum Access
    Replies: 3
    Last Post: 04-10-2015, 09:26 AM
  4. Error 3021 no current record
    By bbrazeau in forum Programming
    Replies: 10
    Last Post: 12-13-2012, 04:22 PM
  5. Replies: 8
    Last Post: 05-16-2011, 06:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums