Problem adding new record to table via form - error 2105 "You can'tgo to the specified record"

M

Martin

It's a long time since I did any Access stuff, but I have created a DB
for a client's computer assets - nothing to complicated. However, I
have problems adding new records. On load, the form sets the
AllowAdditions AllowEdits and AllowDeletions to False. On current, it
does the same unless a new record is being added. My 'New Record'
button sets these to True. Sometimes I can add a new record straight
away, but other times I have to refresh, and/or go to the last record
before I can add a new record. I can't seem to identify a pattern. I
set the error trap to ignore error 2105 but it just leaves me in edit
mode, and not on a new record. There are two subforms with a many to
one relationship with enforced referential integrity. Any suggestions?
Code is below.

Private Sub Form_Current()
Call ToggleControl(Me, Me.NewRecord)
End Sub

Private Sub Form_Load()
Call ToggleControl(Me, False)
End Sub

Private Sub btn_new_Click()
On Error GoTo Err_btn_new_Click
Call ToggleControl(Me, True)
Me.Refresh
DoCmd.GoToRecord , , acNewRec
Exit_btn_new_Click:
Exit Sub
Err_btn_new_Click:
MsgBox Err.Description
Resume Exit_btn_new_Click
End Sub

Sub ToggleControl(frm As Form, AllowEdit As Integer)
Dim ctl As Control
Dim intI As Integer, intCanEdit As Integer
Const conTransparent = 0
Const conWhite = 16777215
Const conGreen = 10092390
Const conRed = 16750950
Const conGrey = 15527148
For Each ctl In frm.Controls
With ctl
Select Case .ControlType
Case acTextBox
If AllowEdit = True Then
.BackColor = conGreen
Else
.BackColor = conGrey
End If
Case acComboBox
If AllowEdit = True Then
.BackColor = conGreen
Else
.BackColor = conGrey
End If
Case acSubform
If AllowEdit = True Then
.BorderColor = conGreen
.Locked = False
Else
.BorderColor = conGrey
.Locked = True
End If
End Select
End With
Next ctl
If AllowEdit = True Then
With frm
.AllowAdditions = True
.AllowDeletions = True
.AllowEdits = True
.Refresh
End With
Else
With frm
.AllowAdditions = False
.AllowDeletions = False
.AllowEdits = False
.Refresh
End With
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top