Create Record Only from the Command Button

  • Thread starter Thread starter Peter
  • Start date Start date
P

Peter

Hi all again...

I have a subform with a create new record command button. I have added the
following code:

Private Sub Create_a_new_case_Click()
On Error GoTo Err_Create_a_new_case_Click

DoCmd.GoToRecord , , acNewRec
[Alert].SetFocus
Me.Signature = Forms![Username Form].[Operator]
Exit_Create_a_new_case_Click:
Exit Sub

Err_Create_a_new_case_Click:
MsgBox Err.Description
Resume Exit_Create_a_new_case_Click

End Sub

How can i prevent the user from creating a new record other then clicking on
this command button...otherwise i will not be able to populate/pick up the
FOSUnerName..Thanks for your patiance..
 
Why not work with the events in Access?

Take advantage of the fact that it fires the form's BeforeInsert event when
you start to add a new record, so remove the "Me.Sig..." line from your
code, and put it in that event instead:

Private Sub Form_BeforeInsert(Cancel As Integer)
Me.Signature = Forms![Username Form].[Operator]
End Sub
 
Thank you Allen, this works fine. One question remains regarding the Insert
Event...what happenes if that specific textfield becomes edited at a later
moment...
i do not want the Me.Signature = Forms![Username Form].[Operator] to
edit..since teh signature = creator of this record...

Allen Browne said:
Why not work with the events in Access?

Take advantage of the fact that it fires the form's BeforeInsert event when
you start to add a new record, so remove the "Me.Sig..." line from your
code, and put it in that event instead:

Private Sub Form_BeforeInsert(Cancel As Integer)
Me.Signature = Forms![Username Form].[Operator]
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Peter said:
Hi all again...

I have a subform with a create new record command button. I have added the
following code:

Private Sub Create_a_new_case_Click()
On Error GoTo Err_Create_a_new_case_Click

DoCmd.GoToRecord , , acNewRec
[Alert].SetFocus
Me.Signature = Forms![Username Form].[Operator]
Exit_Create_a_new_case_Click:
Exit Sub

Err_Create_a_new_case_Click:
MsgBox Err.Description
Resume Exit_Create_a_new_case_Click

End Sub

How can i prevent the user from creating a new record other then clicking
on
this command button...otherwise i will not be able to populate/pick up the
FOSUnerName..Thanks for your patiance..
 
Set the Locked property of this text box to Yes, so the user can't change
it.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Peter said:
Thank you Allen, this works fine. One question remains regarding the
Insert
Event...what happenes if that specific textfield becomes edited at a later
moment...
i do not want the Me.Signature = Forms![Username Form].[Operator] to
edit..since teh signature = creator of this record...

Allen Browne said:
Why not work with the events in Access?

Take advantage of the fact that it fires the form's BeforeInsert event
when
you start to add a new record, so remove the "Me.Sig..." line from your
code, and put it in that event instead:

Private Sub Form_BeforeInsert(Cancel As Integer)
Me.Signature = Forms![Username Form].[Operator]
End Sub

Peter said:
Hi all again...

I have a subform with a create new record command button. I have added
the
following code:

Private Sub Create_a_new_case_Click()
On Error GoTo Err_Create_a_new_case_Click

DoCmd.GoToRecord , , acNewRec
[Alert].SetFocus
Me.Signature = Forms![Username Form].[Operator]
Exit_Create_a_new_case_Click:
Exit Sub

Err_Create_a_new_case_Click:
MsgBox Err.Description
Resume Exit_Create_a_new_case_Click

End Sub

How can i prevent the user from creating a new record other then
clicking
on
this command button...otherwise i will not be able to populate/pick up
the
FOSUnerName..Thanks for your patiance..
 
Back
Top