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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Good Form Design - advice needed 2

Status
Not open for further replies.

frantik

Technical User
Nov 9, 2002
93
GB
Hi

I have a multi - user application - where users enter data though a form that contains a number of subforms.

Users can also browse and edit data depending on access rights and various criteria.

Although it is the same design I have one form for entering, one for editing and one for browsing - one for other criteria however - I am using mostly the same sub-forms - so a user who is editting a record currently opens a different main form from those entering new data but works on some of the same sub-forms.

Will this cause problems with multi users using it? Can anyone tell me a better way of doing this?

Thanks
 
I tend to re-use the same form for all purposes. The code below locks/unlocks the controls in the detail section of a form. It also changes the color according to the Locked state.


Sub LockControls(frm As Form, YesOrNo As Boolean)
Const LockedColor = 16777164
Const UnLockedColor = -2147483643

Dim ctr As Control
Dim BackgroundColor As String
On Error GoTo ErrHandler

If YesOrNo Then
BackgroundColor = LockedColor
Else
BackgroundColor = UnLockedColor
End If

For Each ctr In frm.Section(0).Controls
ctr.Locked = YesOrNo
ctr.BackColor = BackgroundColor
ResumePoint:
Next
Exit Sub

ErrHandler:
Resume ResumePoint
End Sub


I use it in the Current event of each form:

Private Sub Form_Current()
Call LockControls(Me, Not NewRecord)
End Sub

This locks an existing record and unlocks a new one. Especially useful when careless users attempt to type something when they shouldn't...


To unlock an existing record (and edit it), I use a command button:

Private Sub butEdit_Click()
Dim ctr As Control
Set ctr = Screen.PreviousControl
Call LockControls(Me, False)
ctr.SetFocus
Set ctr = Nothing
End Sub

This saves me from coding three forms that are based on the same data.

HTH



[pipe]
Daniel Vlas
Systems Consultant

 
Thank you Danial - I can sort of follow things - how do you get yesorno? Sorry - I am an ameteur!!

Thanks
 
YesOrNo is an argument that you pass to the procedure. Same applies to frm:

Call LockControls(Forms!Employees.Form, True)

will lock the controls on the form Employees

Call LockControls(Forms!Employees.Form, False)
will unlock the controls on form Employees

Call LockControls(Me, True)
will lock the controls on the form from where you call the procedure

Call LockControls(Me, False)
will unlock the controls


Call LockControls(Me, Not NewRecord)

will parse NewRecord to True if it's a new record or to False if it's an existing record. The leading Not reverses the value and passes it to the procedure.

Just paste the procedure LockControls into a module.

Then go to the form, open it in design view, go to View-Code, and paste the Form_Current procedure. Compile the code and open the form. You will see that existing records cannot be edited, but if you go to a new record everything is unlocked. If it does not work, display the properties of the form, go to the OnCurrent event line and double click it (make sure that [Event Procedure] is displayed there).

When you save the module, do NOT call it LockControls...


Good luck




[pipe]
Daniel Vlas
Systems Consultant

 
Thanks again - that will be really helpful One other quick Q?

Each of my forms is based on a different query - How do I tell the form when I open it which query to be based on? - the query it is based on is dependant on which button is clicked.

I have the DoCmd.OpenForm stDocName, , , stLinkCriteria set for each button - is there anyway I can specify the record source at the same time?

Thanks
 
Try specifying the recordsource in the OpenArgs section:

DoCmd.OpenForm "stDocName", , , _
strLinkCriteria, , , "QueryName"

And in the form stDocName Open event:

Private Sub Form_Open(Cancel As Integer)
If Nz(OpenArgs, &quot;&quot;)<>&quot;&quot; then
Me.RecordSource = OpenArgs
End If
End Sub

HTH


[pipe]
Daniel Vlas
Systems Consultant

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top