473,387 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Restricting data Entry on a form

16
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 :)
Feb 23 '15 #1

✓ answered by jforbes

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:
Expand|Select|Wrap|Line Numbers
  1. Public Function LockBoundControls(frm As Form, bLock As Boolean, ParamArray avarExceptionList())
  2. On Error GoTo Err_Handler
  3.     'Purpose:   Lock the bound controls and prevent deletes on the form any its subforms.
  4.     'Arguments  frm = the form to be locked
  5.     '           bLock = True to lock, False to unlock.
  6.     '           avarExceptionList: Names of the controls NOT to lock (variant array of strings).
  7.     'Usage:     Call LockBoundControls(Me. True)
  8.     Dim ctl As Control      'Each control on the form
  9.     Dim lngI As Long        'Loop controller.
  10.     Dim bSkip As Boolean
  11.  
  12.     'Save any edits.
  13.     If frm.Dirty Then
  14.         frm.Dirty = False
  15.     End If
  16.     'Block deletions.
  17.     frm.AllowDeletions = Not bLock
  18.  
  19.     For Each ctl In frm.Controls
  20.         Select Case ctl.ControlType
  21.         Case acTextBox, acComboBox, acListBox, acOptionGroup, acCheckBox, acOptionButton, acToggleButton
  22.             'Lock/unlock these controls if bound to fields.
  23.             bSkip = False
  24.             For lngI = LBound(avarExceptionList) To UBound(avarExceptionList)
  25.                 If avarExceptionList(lngI) = ctl.Name Then
  26.                     bSkip = True
  27.                     Exit For
  28.                 End If
  29.             Next
  30.             If Not bSkip Then
  31.                 If HasProperty(ctl, "ControlSource") Then
  32.                     If Len(ctl.ControlSource) > 0 And Not ctl.ControlSource Like "=*" Then
  33.                         If ctl.Locked <> bLock Then
  34.                             ctl.Locked = bLock
  35.                         End If
  36.                     End If
  37.                 End If
  38.             End If
  39.  
  40.         Case acSubform
  41.             'Recursive call to handle all subforms.
  42.             bSkip = False
  43.             For lngI = LBound(avarExceptionList) To UBound(avarExceptionList)
  44.                 If avarExceptionList(lngI) = ctl.Name Then
  45.                     bSkip = True
  46.                     Exit For
  47.                 End If
  48.             Next
  49.             If Not bSkip Then
  50.                 If Len(Nz(ctl.SourceObject, vbNullString)) > 0 Then
  51.                     ctl.Form.AllowDeletions = Not bLock
  52.                     ctl.Form.AllowAdditions = Not bLock
  53.                     Call LockBoundControls(ctl.Form, bLock)
  54.                 End If
  55.             End If
  56.  
  57.         Case acLabel, acLine, acRectangle, acCommandButton, acTabCtl, acPage, acPageBreak, acImage, acObjectFrame
  58.             'Do nothing
  59.  
  60.         Case Else
  61.             'Includes acBoundObjectFrame, acCustomControl
  62.             Debug.Print ctl.Name & " not handled " & Now()
  63.         End Select
  64.     Next
  65.  
  66.     'Set the visual indicators on the form.
  67.     On Error Resume Next
  68.     frm.cmdLock.Caption = IIf(bLock, "Un&lock", "&Lock")
  69.     frm!rctLock.Visible = bLock
  70.  
  71.  
  72. Exit_Handler:
  73.     Set ctl = Nothing
  74.     Exit Function
  75.  
  76. Err_Handler:
  77.     MsgBox "Error " & Err.Number & " - " & Err.Description
  78.     Resume Exit_Handler
  79. End Function
  80.  
  81. Public Function HasProperty(obj As Object, strPropName As String) As Boolean
  82.     'Purpose:   Return true if the object has the property.
  83.     Dim varDummy As Variant
  84.     On Error Resume Next
  85.     varDummy = obj.Properties(strPropName)
  86.     HasProperty = (Err.Number = 0)
  87. End Function

4 1880
jforbes
1,107 Expert 1GB
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:
Expand|Select|Wrap|Line Numbers
  1. Private Sub secureForm()
  2.     LockBoundControls(Me, (Len(Me.cboCustomer.Value)=0), "cboCustomer")
  3. End Sub
  4.  
Feb 23 '15 #2
RaoAli
16
thank you for the response, but what is this Lockboundcontrol()function?
Feb 24 '15 #3
jforbes
1,107 Expert 1GB
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:
Expand|Select|Wrap|Line Numbers
  1. Public Function LockBoundControls(frm As Form, bLock As Boolean, ParamArray avarExceptionList())
  2. On Error GoTo Err_Handler
  3.     'Purpose:   Lock the bound controls and prevent deletes on the form any its subforms.
  4.     'Arguments  frm = the form to be locked
  5.     '           bLock = True to lock, False to unlock.
  6.     '           avarExceptionList: Names of the controls NOT to lock (variant array of strings).
  7.     'Usage:     Call LockBoundControls(Me. True)
  8.     Dim ctl As Control      'Each control on the form
  9.     Dim lngI As Long        'Loop controller.
  10.     Dim bSkip As Boolean
  11.  
  12.     'Save any edits.
  13.     If frm.Dirty Then
  14.         frm.Dirty = False
  15.     End If
  16.     'Block deletions.
  17.     frm.AllowDeletions = Not bLock
  18.  
  19.     For Each ctl In frm.Controls
  20.         Select Case ctl.ControlType
  21.         Case acTextBox, acComboBox, acListBox, acOptionGroup, acCheckBox, acOptionButton, acToggleButton
  22.             'Lock/unlock these controls if bound to fields.
  23.             bSkip = False
  24.             For lngI = LBound(avarExceptionList) To UBound(avarExceptionList)
  25.                 If avarExceptionList(lngI) = ctl.Name Then
  26.                     bSkip = True
  27.                     Exit For
  28.                 End If
  29.             Next
  30.             If Not bSkip Then
  31.                 If HasProperty(ctl, "ControlSource") Then
  32.                     If Len(ctl.ControlSource) > 0 And Not ctl.ControlSource Like "=*" Then
  33.                         If ctl.Locked <> bLock Then
  34.                             ctl.Locked = bLock
  35.                         End If
  36.                     End If
  37.                 End If
  38.             End If
  39.  
  40.         Case acSubform
  41.             'Recursive call to handle all subforms.
  42.             bSkip = False
  43.             For lngI = LBound(avarExceptionList) To UBound(avarExceptionList)
  44.                 If avarExceptionList(lngI) = ctl.Name Then
  45.                     bSkip = True
  46.                     Exit For
  47.                 End If
  48.             Next
  49.             If Not bSkip Then
  50.                 If Len(Nz(ctl.SourceObject, vbNullString)) > 0 Then
  51.                     ctl.Form.AllowDeletions = Not bLock
  52.                     ctl.Form.AllowAdditions = Not bLock
  53.                     Call LockBoundControls(ctl.Form, bLock)
  54.                 End If
  55.             End If
  56.  
  57.         Case acLabel, acLine, acRectangle, acCommandButton, acTabCtl, acPage, acPageBreak, acImage, acObjectFrame
  58.             'Do nothing
  59.  
  60.         Case Else
  61.             'Includes acBoundObjectFrame, acCustomControl
  62.             Debug.Print ctl.Name & " not handled " & Now()
  63.         End Select
  64.     Next
  65.  
  66.     'Set the visual indicators on the form.
  67.     On Error Resume Next
  68.     frm.cmdLock.Caption = IIf(bLock, "Un&lock", "&Lock")
  69.     frm!rctLock.Visible = bLock
  70.  
  71.  
  72. Exit_Handler:
  73.     Set ctl = Nothing
  74.     Exit Function
  75.  
  76. Err_Handler:
  77.     MsgBox "Error " & Err.Number & " - " & Err.Description
  78.     Resume Exit_Handler
  79. End Function
  80.  
  81. Public Function HasProperty(obj As Object, strPropName As String) As Boolean
  82.     'Purpose:   Return true if the object has the property.
  83.     Dim varDummy As Variant
  84.     On Error Resume Next
  85.     varDummy = obj.Properties(strPropName)
  86.     HasProperty = (Err.Number = 0)
  87. End Function
Feb 24 '15 #4
RaoAli
16
I got this and worked fine...thank you once again :)
Mar 3 '15 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
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...
2
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...
3
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...
2
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...
1
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...
5
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...
2
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...
2
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...
0
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...
1
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...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
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,...
0
Oralloy
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,...
0
jinu1996
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.