Solved Hide/show new record in continuous form (1 Viewer)

Kayleigh

Member
Local time
Today, 06:09
Joined
Sep 24, 2020
Messages
706
Hi there,
Have a continuous form which shows all previous records fine. Since I don't want the new records line displayed, I have allowAdditions = false in the onCurrent event. However the command button to add a new record is always bringing up an error that it can't go to the specified record. Here is my code - what have I done wrong?
Code:
Private Sub cmdAddNew_Click()
Me.AllowAdditions = True
DoCmd.GoToRecord , , acNewRec
If IsNothing(Me.fldRStaffID) Then
Me.fldRStaffID = Forms!frmLogin!cmbstaff
Me.fldRDate = Now
End If
End Sub
When I miss out the doCmd.GoToRecord...it opens a new record but misses the if loop.
Any suggestions?
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:09
Joined
Oct 29, 2018
Messages
21,455
Hi. I'm just a little confused. Where is your button located? I don't understand this part.
When I miss out the doCmd.GoToRecord...it opens a new record but misses the if loop.
Is it "opening" another form? Have you considered using the Default Value property?
 

Kayleigh

Member
Local time
Today, 06:09
Joined
Sep 24, 2020
Messages
706
This button is on the same form. It should go to a new record on continuous form and add the default data as specified in code.
But when try changing to isNull still getting this error message...
 

Attachments

  • error 2105.png
    error 2105.png
    5.4 KB · Views: 346

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 13:09
Joined
May 7, 2009
Messages
19,229
i see you are resetting AllowAdditions on the Current event of the Form.
add another form-variable:
Code:
Option Compare Database
Option Explicit

'arnelgp
Dim bolPass As Boolean

Private Sub Form_Current()
    If Not bolPass Then
        Me.AllowAdditions = False
    End If
    bolPass = False
End Sub

Private Sub cmdAddNew_Click()
'arnelgp
'prevent current from resetting
'the Form's AllowAddtions property
bolPass = True
'
Me.AllowAdditions = True
DoCmd.GoToRecord , , acNewRec
If IsNull(Me.fldRStaffID) Then
    Me.fldRStaffID = Forms!frmLogin!cmbstaff
    Me.fldRDate = Now
End If
End Sub
 
Last edited:

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 06:09
Joined
Sep 12, 2006
Messages
15,641
Do you mean the asterisk button in the navigation keys is enabled? I would have thought if allowadditions is false, then the asterisk would be disabled also.
 

Users who are viewing this thread

Top Bottom