Error Code 2105 (1 Viewer)

basilyos

Registered User.
Local time
Today, 12:39
Joined
Jan 13, 2014
Messages
252
hello guys,


i have a form that is bound to a table


am let the form go to the last record then showing a message to let the client now the number of the last file saved then push the form to go to a new record so the client continue saving new files

Code:
Private Sub Form_Load()

    DoCmd.GoToRecord , , acLast
    MsgBox ("the last Saved File Was Number " & Me.txt_Record_Number)
    DoCmd.GoToRecord , , acNewRec
    
End Sub
this is what am getting when the form load


Run-time error '2105'
You Can't go to the specified record


and when i debug am going to this line


Code:
DoCmd.GoToRecord , , acNewRec
any help ?
 

Minty

AWF VIP
Local time
Today, 20:39
Joined
Jul 26, 2013
Messages
10,371
How are you opening the form, and do you have it set to data entry = Yes in design mode?
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 12:39
Joined
Aug 30, 2003
Messages
36,125
Also is Allow Additions set to Yes, and does the record source of the form allow new records to be added directly if it's a query?
 

basilyos

Registered User.
Local time
Today, 12:39
Joined
Jan 13, 2014
Messages
252
am opening the form from another form using this command


Code:
DoCmd.OpenForm "frm_Personal_Sanctions_Entry", acNormal, , "[PID] = " & [PID]


Data Entry set to no
Allow Additions set to yes
 

basilyos

Registered User.
Local time
Today, 12:39
Joined
Jan 13, 2014
Messages
252
am filtering the form using PID coz every client have his own files to save
 

Minty

AWF VIP
Local time
Today, 20:39
Joined
Jul 26, 2013
Messages
10,371
I think a filtered form won't let you go to a new record, as the new record won't have the PID you are requesting.

Personally I think you'd be better off getting the last Record ID using a DLookup, and just opening the form directly on a new record.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 12:39
Joined
Aug 30, 2003
Messages
36,125
In an extremely brief test, a form based on a table opened with a wherecondition still allowed new records. Can yo attach your db here?
 

basilyos

Registered User.
Local time
Today, 12:39
Joined
Jan 13, 2014
Messages
252
i attached a small copy of my database i hope could some one help me
 

Attachments

  • Data.accdb
    788 KB · Views: 56

pbaldy

Wino Moderator
Staff member
Local time
Today, 12:39
Joined
Aug 30, 2003
Messages
36,125

pbaldy

Wino Moderator
Staff member
Local time
Today, 12:39
Joined
Aug 30, 2003
Messages
36,125
For chuckles, tried this which also works, which again points to the message box:

Code:
    Dim lngNumber             As Long
    
    DoCmd.GoToRecord , , acLast
    lngNumber = Me.txt_Record_Number
    DoCmd.GoToRecord , , acNewRec
    MsgBox lngNumber
 

basilyos

Registered User.
Local time
Today, 12:39
Joined
Jan 13, 2014
Messages
252
For chuckles, tried this which also works, which again points to the message box:

Code:
    Dim lngNumber             As Long
    
    DoCmd.GoToRecord , , acLast
    lngNumber = Me.txt_Record_Number
    DoCmd.GoToRecord , , acNewRec
    MsgBox lngNumber


thank you so much
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 12:39
Joined
Aug 30, 2003
Messages
36,125
No problem. It is curious that having the message box before the GoToRecord causes the error.
 

Minty

AWF VIP
Local time
Today, 20:39
Joined
Jul 26, 2013
Messages
10,371
No problem. It is curious that having the message box before the GoToRecord causes the error.

That is weird. Good spot though.
I wonder if the handler for the message box causes some strange record lock somehow?
 

JHB

Have been here a while
Local time
Today, 21:39
Joined
Jun 17, 2012
Messages
7,732
..
I wonder if the handler for the message box causes some strange record lock somehow?
No, but the focus move away from the form, so if you've have "Me.SetFocus" just before "DoCmd.GoToRecord" the problem is gone.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 12:39
Joined
Aug 30, 2003
Messages
36,125
No, but the focus move away from the form, so if you've have "Me.SetFocus" just before "DoCmd.GoToRecord" the problem is gone.

Ah, so it does. Good catch! I hadn't considered that.
 

Users who are viewing this thread

Top Bottom