Run-Time error '2105' You can't go to the specified record.

MHamid

Active Member
Joined
Jan 31, 2013
Messages
472
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hello,

I am using the below code for required fields in the form's Before Update event.

Code:
For Each ctl In Me.Controls
    If ctl.ControlType = acTextBox Then
        If ctl.Tag = "*" And Trim(ctl & "") = "" Then
            msg = "Data Required for '" & ctl.Name & "' field!" & nl & _
            "You can't save this record until this data is provided!" & nl & _
            "Enter the data and try again . . . "
            Style = vbCritical + vbOKOnly
            Title = "Required Data..."
            MsgBox msg, Style, Title
            ctl.SetFocus
            Cancel = True
            Exit For
        End If
    End If
Next

When I click on my Add Record Button I get the error message "Run-Time error '2105' You can't go to the specified record." and in my AddRecord button code the go to new record line is highlighted (in red text elow).

Code:
Private Sub AddRecord_Click()
Dim ID As Long
 
ID = DMax("RefID", "QAMaster")
[COLOR=#FF0000]DoCmd.GoToRecord , , acNewRec[/COLOR]
Me.Approved = DLookup("ApprovedBy", "QAMaster", "RefID=" & ID)
Me.CycleMonth = DLookup("CycleMonth", "QAMaster", "RefID=" & ID)
Me.DateReviewed = DLookup("DateReviewed", "QAMaster", "RefID=" & ID)
Me.ReportType = DLookup("ReportType", "QAMaster", "RefID=" & ID)
Me.MainSection = DLookup("MainSection", "QAMaster", "RefID=" & ID)
Me.TopicSection = DLookup("TopicSection", "QAMaster", "RefID=" & ID)
Me.ReviewerType = DLookup("ReviewerType", "QAMaster", "RefID=" & ID)
Me.Reviewer = DLookup("Reviewer", "QAMaster", "RefID=" & ID)
Me.ReviewerReportArea = DLookup("ReviewerReportArea", "QAMaster", "RefID=" & ID)
Me.Individual = DLookup("OwnershipIndividual", "QAMaster", "RefID=" & ID)
Me.Team = DLookup("OwnershipTeam", "QAMaster", "RefID=" & ID)

Me.EnteredBy = Environ("USERNAME")
Me.DateEntered = Format(DateValue(Now()), "Short Date")
Me.txtCount.SetFocus
 
Me.txtOther.Visible = False
Me.txtOther2.Visible = False
End Sub

I need the required field code to ensure all required fields are filled. Then I want it to go to the blank field and not add the record until all fields are filled.


Thank you
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Not sure what you are asking here -- required field code in a before update event should have nothing to do with going to a new record (new records by definition won't be anything that is being updated because they are new records, not records being saved).
 
Upvote 0
Hello,

I see my mistake. The record was already in a new record, which is why it was erring out in the new record portion of the code. I corrected this to:

Code:
Private Sub AddRecord_Click()
Dim ID As Long
 
    ID = DMax("RefID", "QAMaster")
[COLOR=#FF0000]If Not Me.NewRecord Then
    DoCmd.GoToRecord , , acNewRec
End If[/COLOR]
    Me.Approved = DLookup("ApprovedBy", "QAMaster", "RefID=" & ID)
    Me.CycleMonth = DLookup("CycleMonth", "QAMaster", "RefID=" & ID)
    Me.DateReviewed = DLookup("DateReviewed", "QAMaster", "RefID=" & ID)
    Me.ReportType = DLookup("ReportType", "QAMaster", "RefID=" & ID)
    Me.MainSection = DLookup("MainSection", "QAMaster", "RefID=" & ID)
    Me.TopicSection = DLookup("TopicSection", "QAMaster", "RefID=" & ID)
    Me.ReviewerType = DLookup("ReviewerType", "QAMaster", "RefID=" & ID)
    Me.Reviewer = DLookup("Reviewer", "QAMaster", "RefID=" & ID)
    Me.ReviewerReportArea = DLookup("ReviewerReportArea", "QAMaster", "RefID=" & ID)
    Me.Individual = DLookup("OwnershipIndividual", "QAMaster", "RefID=" & ID)
    Me.Team = DLookup("OwnershipTeam", "QAMaster", "RefID=" & ID)

    Me.EnteredBy = Environ("USERNAME")
    Me.DateEntered = Format(DateValue(Now()), "Short Date")
    Me.txtCount.SetFocus
 
    Me.txtOther.Visible = False
    Me.txtOther2.Visible = False
End Sub

Now I'm not getting the error message anymore. However, the required fields code is not ensuring all required fields are filled. I will do a new post for this issue.


Thank you
 
Upvote 0
okay. make sure you have the asterisk in the tag property of the required fields you want to validate.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,185
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top