I have form to record payment from a customer. I want to lock the payments details in text boxes on the form unless the user selects some customer from a customers combo.
hope i conveyed my idea :)
The LockBoundControls() Function is provided by the above link.
Here is a copy of it, but the link will give greater detail of what is happening: - Public Function LockBoundControls(frm As Form, bLock As Boolean, ParamArray avarExceptionList())
-
On Error GoTo Err_Handler
-
'Purpose: Lock the bound controls and prevent deletes on the form any its subforms.
-
'Arguments frm = the form to be locked
-
' bLock = True to lock, False to unlock.
-
' avarExceptionList: Names of the controls NOT to lock (variant array of strings).
-
'Usage: Call LockBoundControls(Me. True)
-
Dim ctl As Control 'Each control on the form
-
Dim lngI As Long 'Loop controller.
-
Dim bSkip As Boolean
-
-
'Save any edits.
-
If frm.Dirty Then
-
frm.Dirty = False
-
End If
-
'Block deletions.
-
frm.AllowDeletions = Not bLock
-
-
For Each ctl In frm.Controls
-
Select Case ctl.ControlType
-
Case acTextBox, acComboBox, acListBox, acOptionGroup, acCheckBox, acOptionButton, acToggleButton
-
'Lock/unlock these controls if bound to fields.
-
bSkip = False
-
For lngI = LBound(avarExceptionList) To UBound(avarExceptionList)
-
If avarExceptionList(lngI) = ctl.Name Then
-
bSkip = True
-
Exit For
-
End If
-
Next
-
If Not bSkip Then
-
If HasProperty(ctl, "ControlSource") Then
-
If Len(ctl.ControlSource) > 0 And Not ctl.ControlSource Like "=*" Then
-
If ctl.Locked <> bLock Then
-
ctl.Locked = bLock
-
End If
-
End If
-
End If
-
End If
-
-
Case acSubform
-
'Recursive call to handle all subforms.
-
bSkip = False
-
For lngI = LBound(avarExceptionList) To UBound(avarExceptionList)
-
If avarExceptionList(lngI) = ctl.Name Then
-
bSkip = True
-
Exit For
-
End If
-
Next
-
If Not bSkip Then
-
If Len(Nz(ctl.SourceObject, vbNullString)) > 0 Then
-
ctl.Form.AllowDeletions = Not bLock
-
ctl.Form.AllowAdditions = Not bLock
-
Call LockBoundControls(ctl.Form, bLock)
-
End If
-
End If
-
-
Case acLabel, acLine, acRectangle, acCommandButton, acTabCtl, acPage, acPageBreak, acImage, acObjectFrame
-
'Do nothing
-
-
Case Else
-
'Includes acBoundObjectFrame, acCustomControl
-
Debug.Print ctl.Name & " not handled " & Now()
-
End Select
-
Next
-
-
'Set the visual indicators on the form.
-
On Error Resume Next
-
frm.cmdLock.Caption = IIf(bLock, "Un&lock", "&Lock")
-
frm!rctLock.Visible = bLock
-
-
-
Exit_Handler:
-
Set ctl = Nothing
-
Exit Function
-
-
Err_Handler:
-
MsgBox "Error " & Err.Number & " - " & Err.Description
-
Resume Exit_Handler
-
End Function
-
-
Public Function HasProperty(obj As Object, strPropName As String) As Boolean
-
'Purpose: Return true if the object has the property.
-
Dim varDummy As Variant
-
On Error Resume Next
-
varDummy = obj.Properties(strPropName)
-
HasProperty = (Err.Number = 0)
-
End Function
4 1880
I would recommend using this code provided by Allen Browne: http://allenbrowne.com/ser-56.html
Create a Subroutine that Locks the Form if a Customer isn't selected, and Unlocks if the Customer is selected. Then call the Subroutine from the Form's OnCurrent event and the Customer ComboBox AfterUpdate Event.
The Sub could look like this: -
Private Sub secureForm()
-
LockBoundControls(Me, (Len(Me.cboCustomer.Value)=0), "cboCustomer")
-
End Sub
-
thank you for the response, but what is this Lockboundcontrol()function?
The LockBoundControls() Function is provided by the above link.
Here is a copy of it, but the link will give greater detail of what is happening: - Public Function LockBoundControls(frm As Form, bLock As Boolean, ParamArray avarExceptionList())
-
On Error GoTo Err_Handler
-
'Purpose: Lock the bound controls and prevent deletes on the form any its subforms.
-
'Arguments frm = the form to be locked
-
' bLock = True to lock, False to unlock.
-
' avarExceptionList: Names of the controls NOT to lock (variant array of strings).
-
'Usage: Call LockBoundControls(Me. True)
-
Dim ctl As Control 'Each control on the form
-
Dim lngI As Long 'Loop controller.
-
Dim bSkip As Boolean
-
-
'Save any edits.
-
If frm.Dirty Then
-
frm.Dirty = False
-
End If
-
'Block deletions.
-
frm.AllowDeletions = Not bLock
-
-
For Each ctl In frm.Controls
-
Select Case ctl.ControlType
-
Case acTextBox, acComboBox, acListBox, acOptionGroup, acCheckBox, acOptionButton, acToggleButton
-
'Lock/unlock these controls if bound to fields.
-
bSkip = False
-
For lngI = LBound(avarExceptionList) To UBound(avarExceptionList)
-
If avarExceptionList(lngI) = ctl.Name Then
-
bSkip = True
-
Exit For
-
End If
-
Next
-
If Not bSkip Then
-
If HasProperty(ctl, "ControlSource") Then
-
If Len(ctl.ControlSource) > 0 And Not ctl.ControlSource Like "=*" Then
-
If ctl.Locked <> bLock Then
-
ctl.Locked = bLock
-
End If
-
End If
-
End If
-
End If
-
-
Case acSubform
-
'Recursive call to handle all subforms.
-
bSkip = False
-
For lngI = LBound(avarExceptionList) To UBound(avarExceptionList)
-
If avarExceptionList(lngI) = ctl.Name Then
-
bSkip = True
-
Exit For
-
End If
-
Next
-
If Not bSkip Then
-
If Len(Nz(ctl.SourceObject, vbNullString)) > 0 Then
-
ctl.Form.AllowDeletions = Not bLock
-
ctl.Form.AllowAdditions = Not bLock
-
Call LockBoundControls(ctl.Form, bLock)
-
End If
-
End If
-
-
Case acLabel, acLine, acRectangle, acCommandButton, acTabCtl, acPage, acPageBreak, acImage, acObjectFrame
-
'Do nothing
-
-
Case Else
-
'Includes acBoundObjectFrame, acCustomControl
-
Debug.Print ctl.Name & " not handled " & Now()
-
End Select
-
Next
-
-
'Set the visual indicators on the form.
-
On Error Resume Next
-
frm.cmdLock.Caption = IIf(bLock, "Un&lock", "&Lock")
-
frm!rctLock.Visible = bLock
-
-
-
Exit_Handler:
-
Set ctl = Nothing
-
Exit Function
-
-
Err_Handler:
-
MsgBox "Error " & Err.Number & " - " & Err.Description
-
Resume Exit_Handler
-
End Function
-
-
Public Function HasProperty(obj As Object, strPropName As String) As Boolean
-
'Purpose: Return true if the object has the property.
-
Dim varDummy As Variant
-
On Error Resume Next
-
varDummy = obj.Properties(strPropName)
-
HasProperty = (Err.Number = 0)
-
End Function
I got this and worked fine...thank you once again :)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Rajesh |
last post by:
dear all,
as of now, am working on a simple access database with a normal data
entry form
Can I design a form in HTML for data entry, and the same be linked to an
access database where the...
|
by: Iain Miller |
last post by:
Struggling a bit here & would be grateful for any help.
I have a table which has a list of people in it. Each person has a unique ID
automatically allocated by Access but also belongs to one of 5...
|
by: intl04 |
last post by:
Is it possible to create a Word form as the data entry form for an
Access database? I didn't see any reference to this possibility in my
Access books, so I'm sorry if this is a question that is...
|
by: edworboys |
last post by:
I have designed a data entry form with a number of fields and a sub
form. The first field (Country) is a combo box and the user selects a
country. This, in turn reduces the number of options in the...
|
by: KC |
last post by:
Hello,
I am using Access 2002. WinXP, Template from MS called Orders Mgmt DB.
I have tweaked this DB to work for our small co. It has worked pretty
well up until I made the mistake of deleting...
|
by: Aspnot |
last post by:
Background:
I have a data entry form that is bound to a DataSet. This DataSet contains
9 tables and the form displays data from each table in textboxes, not a
DataGrid. One of the tables in the...
|
by: filbennett |
last post by:
Hi Everyone,
I'm generally unfamiliar with Access form design, but have programmed
Cold Fusion applications for a couple of years.
I'd like to build a data entry form in Access that allows the...
|
by: seltzer |
last post by:
I am using Access 2000 but I also have the 2003 version.
I am working on creating a data entry form in Access for a research study. Since there is a maximum of 255 fields per table in Access, I...
|
by: Tyler |
last post by:
Made a data entry form which is a subform. I made a continuous form
that displays everything entered through the data entry form. The
data entry form displays all of the records. This doesn't...
|
by: Ville Mäkelä |
last post by:
HI,
In my data entry form with combo as well text boxes, I have a commad button which checks for any dublicate data using if clause and Dcount. If there is no dublicates, the data will be...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |