Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

editing

Status
Not open for further replies.

jommyjet

Technical User
May 19, 2003
49
US
I disallowed edits in a form, but there are a few fields I'd like to allow edits to. is there an easier way to do this defining it in a module? thanks
 
Hi!

Instead of disallowing edits on the whole form just set the locked property of the controls you don't want updated to true or set the disabled property to false.

hth


Jeff Bridgham
bridgham@purdue.edu
 
I locked the fields that I don't want to be edited and selected allow edits for the form properties, but I can't enter a new values in the locked fields for a new record. the form is based on a query and I can add records through the query. any ideas? thanks
 
Hi

You've got conflicting requirements here. In your first sentence you say you want to disallow edits (which includes entering a new value) and then you want to enter a new value.

If you want to enter data initially (as a new record) and then prohibit the changing of the entered data once it has been saved then you will have to enter code in the "On Current" event which checks to see if the current record is a new record in which case the fields are unlocked else lock the required fields.

If you want help with the code then let me know.

Tony
 
thanks Tony.that's exactly what I'd like and I'll take your offer of help. I'm not sure where to start.
 
I imagine I need to declare the recordset and the current record

Dim rst As Recordset
dim x as current (or something)
Set rst = currentdb.OpenRecordset()
If x = New Then
unlock
Else
End If

am I off?
 
Private Sub Form_Current()


If intnewrec = True Then
Me!employeeID.locked = false
Me!firstname.Locked = False
Me!lastname.Locked = False



End If
End Sub

is this getting closer?
 
Hi

You don't need to open the recordset as it has already been opened by your forms scource query.

Put the following function in a module. It will also disable the "New Record" button on the record navigation bar at the bottom of your form. (If you have enabled it)

'==================================================
Function IsNewRecord()
'==================================================
'
' stops any form in edit mode from going
' to a blank record
'
' State is True for Enabled or False for Disabled
'
'==================================================
Dim RetVal
On Error Resume Next

RetVal = Screen.ActiveForm.Bookmark
If Err Then
IsNewRecord = True
DoCmd.GoToRecord , , A_LAST
Else
IsNewRecord = False
End If

End Function
===================================================

In the "On Current" event for your form use:

If IsNewRecord = True then
Me!employeeID.locked = false
Me!firstname.Locked = False
Me!lastname.Locked = False
End If

(Rest of OnCurrent code here)

This should sort it! Good luck

Tony
 
Hi!

Sorry I couldn't get back to this until this morning and thanks to Tony for picking up the slack. A couple of things I would like to add. I think you need to relock the text boxes if an existing record is accessed, like this:

If IsNewRecord = True Then
Me!employeeID.locked = Flse
Me!firstname.Locked = False
Me!lastname.Locked = False
Else
Me!employeeID.locked = True
Me!firstname.Locked = True
Me!lastname.Locked = True
End If

Secondly, since employeeID looks like a primary key you might be able to use simpler code like this:

If IsNull(Me!employeeID) = True Then
Me!employeeID.locked = Flse
Me!firstname.Locked = False
Me!lastname.Locked = False
Else
Me!employeeID.locked = True
Me!firstname.Locked = True
Me!lastname.Locked = True
End If

Again, this would be in the Form_Current event procedure.

hth


Jeff Bridgham
bridgham@purdue.edu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top