Me.RecordsetType and NewRecord

  • Thread starter Thread starter H. Martins
  • Start date Start date
H

H. Martins

I want a form to be kept sort of readonly until a newrecord button is
pressed:

In Form_AfterUpdate() I use:

If Me.NewRecord = True Then
Me.RecordsetType = 0 'Dynaset
Else
Me.RecordsetType = 2 'Snapshot
End If

Then, when the button is pressed I use:

Me.RecordsetType = 0 'Dynaset
DoCmd.GoToRecord , , acNewRec

Then I get the message that "you can't go to the specified record"

Can I have some help, please. I also tried Form_BeforeUpdate() and
Form_Current(), I can't get it running.

Can I have some help, pelase?

Thanks
H. Martins
 
H. Martins said:
I want a form to be kept sort of readonly until a newrecord button is
pressed:

In Form_AfterUpdate() I use:

If Me.NewRecord = True Then
Me.RecordsetType = 0 'Dynaset
Else
Me.RecordsetType = 2 'Snapshot
End If

Then, when the button is pressed I use:

Me.RecordsetType = 0 'Dynaset
DoCmd.GoToRecord , , acNewRec

Then I get the message that "you can't go to the specified record"

Can I have some help, please. I also tried Form_BeforeUpdate() and
Form_Current(), I can't get it running.

Can I have some help, pelase?


I don't know exactly what's going on, as I've never tried to manipulate the
form's RecordsetType property on the fly. Does it work at all?

I don't think I'd do it this way, though. Instead, I would manipulate the
form's AllowAdditions property. Something like this:

'----- start of code -----
Private Sub cmdAddRecord_Click()

Me.AllowAdditions = True
RunCommand acCmdRecordsGoToNew

End Sub

Private Sub cmdCancelAdd_Click()

Me.Undo
Me.AllowAdditions = False

End Sub

Private Sub Form_AfterInsert()

Me.AllowAdditions = False

End Sub

Private Sub Form_Current()

If Not Me.NewRecord Then
Me.AllowAdditions = False
End If

End Sub
'----- end of code -----

The AllowEdits and AllowDeletions properties would be set to No in the form
design, and would stay that way unless I wanted to control those operations
also via a command button.
 
Thank you Dirk,

As much as I can see, my problem is not about allowing or not to add
new or delete records.

My problem goes on how to make a form read-only and how to make it
read/wright so that a new record can be added (or deleted).

Me.AllowAdditions just disable the creation of new records, do not
disabling editing already existing records.

Thanks
H. Martins
 
There's also Me.AllowEdits and Me.AllowDeletions, in addition to
Me.AllowAdditions.
 
You could use:

Private Sub Form_Current

me.AllowEdits = me.NewRecord

End Sub

Private sub cmd_Edit_Click

me.AllowEdits = True

End Sub



--
HTH
Dale

email address is invalid
Please reply to newsgroup only.
 
Range-o-Dente da Silva said:
Thank you Dirk,

As much as I can see, my problem is not about allowing or not to add
new or delete records.

My problem goes on how to make a form read-only and how to make it
read/wright so that a new record can be added (or deleted).

Me.AllowAdditions just disable the creation of new records, do not
disabling editing already existing records.

As I mentioned, you can also manipulate the AllowEdits and AllowDeletions
properties in a very similar fashion. It's up to you to decide what you
want to restrict or allow.
 
Hi Dirk,

Me.AllowEdits is much better than Me.RecordsetType

AllowEdits and AllowDeletions is also very handy.

It worked perfectly.

Thanks
HM.
 
Back
Top