One thing leads to another...

Nightowl4933

Tryin' to do it right...
Local time
Today, 12:09
Joined
Apr 27, 2016
Messages
151
I've nearly got my form sorted and, for one reason or another, I've locked all the controls (except command buttons) to ensure users don't accidentally break anything.

The trouble is, they will still need to add and edit records.

I've got the edit bit sorted, by enabling those controls that can be amended when Users click an 'Edit' button (which unlocks the controls) and then 'saves' the record when they click the Save button (which only really locks the controls).

The trouble is, using the standard 'Add New' default macro won't (obviously!) enable the controls, so is there an easier way of adding a new record without having to write an Event Procedure to enable them all and clear their values for a new record?

Thanks - again :o:o
 
You can have code in the current event that tests Me.NewRecord and unlocks controls if it is a new record.
 
Thanks, Paul, but could you be a bit more specific, please?

I'm not currently using an Event, but relying on the default macro wizard.

Pete
 
Last edited:
I don't use macros, so not sure. What version? I doubt this is something a wizard will do. You'd want to test for a new record.
 
Few experienced developers use Macros...they make simple tasks easy, but are very rigid and not practical once the task at hand becomes more complex, as seen here.

Doing as Paul suggested, in Post #2, using VBA code, in an Event Procedure, is really simple, and a good way to get your feet wet using code:

Code:
Private Sub Form_Current()

If Me.NewRecord Then
 Control1.Enabled = True
 Control2.Enabled = True
Else
 Control1.Enabled = False
 Control2.Enabled = False
End If

End Sub
Place this in the code module of your Form, replacing Control1, Control2, etc with the actual names of your Controls.

Linq ;0)>
 
I'm using Access 2007, and I normally use the Code Builder. Howwever, I was hoping to find an easier way of adding a new record without having to enable everything.

Perhaps it's wishful thinknig :-(
 
Few experienced developers use Macros...they make simple tasks easy, but are very rigid and not practical once the task at hand becomes more complex, as seen here.

Doing as Paul suggested, in Post #2, using VBA code, in an Event Procedure, is really simple, and a good way to get your feet wet using code:

Code:
Private Sub Form_Current()

If Me.NewRecord Then
 Control1.Enabled = True
 Control2.Enabled = True
Else
 Control1.Enabled = False
 Control2.Enabled = False
End If

End Sub
Place this in the code module of your Form, replacing Control1, Control2, etc with the actual names of your Controls.

Linq ;0)>

Thnaks, Linq.

With a lot of controls, I was hoping there was an easier way, but I guess not.

Thanks anyway.
 
You can loop controls, using the Tag property to identify the ones to affect.
 
And here's how you do that:

In Form Design View
  • Holding down <Shift> and Left-Click on each Control to be Enabled or Disabled, in turn
  • Go to Properties - Other
  • In the Tag Property box, enter Marked, just like that, no Quotes
  • Click on any other Property in the pane and save Form


Now use this code:

Code:
Private Sub Form_Current()

Dim ctrl As Control

If Me.NewRecord Then

For Each ctrl In Me.Controls
  If ctrl.Tag = "marked" Then
    ctrl.Enabled = True
  End If
Next

Else

For Each ctrl In Me.Controls
  If ctrl.Tag = "marked" Then
    ctrl.Enabled = False
  End If
Next

End If

End Sub

Linq ;0)>
 

Users who are viewing this thread

Back
Top Bottom