GoTo specified record and then New record

Jeff H
3StarLounger
Posts: 316
Joined: 31 Oct 2017, 20:07

GoTo specified record and then New record

Post by Jeff H »

Here's another one:

There is a continuous form where each record is a separate row. The main purpose of the form is for adding records, but I'm not using the Add data mode. When the user opens the form from the dashboard, it opens to a new record with all the previous records available.

What I'm trying to do is give the user some visual orientation. Instead of having only the new record visible, I want them to see the 5 previous records. Below is how I'm trying to do that, but after selecting the fifth from last record, the error says "You can't go to the specified record" to take me to the new record. Is there another way to do this?

Code: Select all

lRecs = DCount("*", "tblwellspring") - 5
sCalled = "frmWellSpring"

With Forms(sCalled)
    DoCmd.SetOrderBy "SingDate"
    DoCmd.GoToRecord , , acGoTo, lRecs
    DoCmd.GoToRecord , , acNewRec
End With

User avatar
HansV
Administrator
Posts: 69412
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: GoTo specified record and then New record

Post by HansV »

Does frmWellSpring have the focus when this code is run?
Regards,
Hans

Jeff H
3StarLounger
Posts: 316
Joined: 31 Oct 2017, 20:07

Re: GoTo specified record and then New record

Post by Jeff H »

Yes.
This code is in the Dashboard button click event, but before this sequence, a standalone procedure called CallAnObject runs. Here's the full click event code. I'm using the public variables and CallAnObject to standardize the opening of objects from the dashboard and returning to the dashboard.

Code: Select all

Private Sub tglWellspringAdd_Click()
Dim lRecs As Long

Me.tglWellspringAdd.Value = False
Me.Visible = False  'This "Me" is the dashboard
lRecs = DCount("*", "tblwellspring") - 5

sCalled = "frmWellSpring"
sObject = "Std_Form"
sCaller = Me.Name

CallAnObject  'This procedure opens the form

With Forms(sCalled)
    DoCmd.SetOrderBy "SingDate"
    DoCmd.GoToRecord , , acGoTo, lRecs
    DoCmd.GoToRecord , , acNewRec
End With

End Sub

User avatar
HansV
Administrator
Posts: 69412
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: GoTo specified record and then New record

Post by HansV »

Could you attach a zipped copy of the database or send it to me?
Regards,
Hans

Jeff H
3StarLounger
Posts: 316
Joined: 31 Oct 2017, 20:07

Re: GoTo specified record and then New record

Post by Jeff H »

Ok. I just sent it.

User avatar
HansV
Administrator
Posts: 69412
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: GoTo specified record and then New record

Post by HansV »

frmWellspring has "Allow Additions" set to No, so you cannot add new records using this form.
Regards,
Hans

Jeff H
3StarLounger
Posts: 316
Joined: 31 Oct 2017, 20:07

Re: GoTo specified record and then New record

Post by Jeff H »

UGH! I completely forgot about that change! I'm using the same form for reviewing/editing and for adding. Unfortunately I forgot that fact when I was going over the reviewing form and disallowed new records.

My apologies!! I'll try to be more alert before wasting your time going forward. :blush: