UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Gotorecord Isn't Available Now, Access 2016    
 
   
DonD
post Sep 29 2016, 11:06 AM
Post#1



Posts: 12
Joined: 13-May 16



I've tried to fix this problem now for 8 hours without success, so it's time to ask for help.

I have a form frmLeadDetails which contains a tabbed control, and one of those tabs contains the subform sfrmLeadsTabTask that contains a list of tasks (records) that pertain to the parent record in frmLeadDetails. If the user double-clicks one of the records in the subform, frmTaskDetails opens to that particular record, and frmTaskDetails contains 3 buttons: btnSaveClose, btnSaveNew and btnCancel.

My problem is this...if the user open's a record in frmTaskDetails, makes a change and then clicks btnSaveNew, the code behind that button saves the record and successfully goes to a new record. But if the user does NOT make a change to the record and clicks btnSaveNew, I get runtime error 2046 that tells me "the command or action 'GoToRecord' isn't available now. The code behind this button is simple and the only difference between the two circumstances I described is whether the record is saved or not. I think I've tried everything under the sun to get it to work without success. Below is the code behind the button. Any ideas?

CODE
Private Sub btnSaveNew_Click()
    If Me.Dirty Then
        Me.Dirty = False
    End If
    DoCmd.GoToRecord , , acNewRec

End Sub
Go to the top of the page
 
BruceM
post Sep 29 2016, 12:09 PM
Post#2


UtterAccess VIP
Posts: 6,563
Joined: 24-May 10
From: Downeast Maine


Can you add a new record using the built in navigation buttons?
Go to the top of the page
 
DonD
post Sep 29 2016, 01:17 PM
Post#3



Posts: 12
Joined: 13-May 16



Yes. I have the navigation buttons turned off, but if I turn them on and run the code until I get the error and then try the navigation buttons, I am able to go to a new record.
Go to the top of the page
 
BruceM
post Sep 29 2016, 01:46 PM
Post#4


UtterAccess VIP
Posts: 6,563
Joined: 24-May 10
From: Downeast Maine


Have you tried leaving out the If, and just having this?

Me.Dirty = False

DoCmd.GoToRecord , , acNewRec

Are there any macros in the button's event properties, or other event procedures for the button? What happens if you create a new command button from scratch, with just the GoToRecord command (or Me.Recordset.AddNew)
Go to the top of the page
 
DonD
post Sep 29 2016, 02:49 PM
Post#5



Posts: 12
Joined: 13-May 16



I did try without the IF and that didn't work. No macros or other event procedures and I did try a new button with just the GoToRecord command and that did not work. But I hadn't tried Me.Recordset.AddNew so before trying that in a button, I tried it in my code instead of DoCmd.GoToRecord,,acNewRec and THAT WORKED! Any idea why?
Go to the top of the page
 
gemmathehusky
post Sep 29 2016, 04:45 PM
Post#6


UtterAccess VIP
Posts: 4,401
Joined: 5-June 07
From: UK


I imagine the save record is failing
what does this code do?

CODE
Private Sub btnSaveNew_Click()
    on error goto fail
    If Me.Dirty Then
        Me.Dirty = False
    End If

    DoCmd.GoToRecord , , acNewRec
    exit sub


fail:
    msgbox "error saving record & vbcrlf & _
     "error: " & err & " Desc: " & err.description
End Sub
Go to the top of the page
 
BruceM
post Sep 30 2016, 06:26 AM
Post#7


UtterAccess VIP
Posts: 6,563
Joined: 24-May 10
From: Downeast Maine


QUOTE
I hadn't tried Me.Recordset.AddNew so before trying that in a button, I tried it in my code instead of DoCmd.GoToRecord,,acNewRec and THAT WORKED! Any idea why?

I really don't know. As a general thing I seek alternatives to DoCmd, but I can't remember why I started doing that in general, or specifically why I started using AddNew, MoveNext, etc. with the Recordset.

I hope somebody weighs in, because I am as curious as you are.
Go to the top of the page
 
projecttoday
post Sep 30 2016, 06:42 AM
Post#8


UtterAccess VIP
Posts: 8,179
Joined: 10-February 04
From: South Charleston, WV


Try DoCmd.GoToRecord acActiveDataObject, , acNewRec
Go to the top of the page
 
cvcaudill
post Mar 18 2017, 10:20 AM
Post#9



Posts: 150
Joined: 28-January 03
From: KY


Thanks, I was having same problem fixed.
Courtney
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    23rd June 2017 - 03:44 PM