Learn Microsoft Access Advanced Programming Techniques, Tips and Tricks.

Time-bound Form Mode Change

Allow data entry or editing on certain period of time otherwise lock the form for data view alone.  The reason to do this may be for time-bound work schedules or some other reason.  Request for a solution to this kind of  action was raised in a Microsoft Access Discussion Forum on the web and I thought I will give it a try and written a program to enable the form for Data Entry/Edit between 06:00 to 07:00 Hours, 11:00 to 13:00 Hours and 17:00 to 19:00 Hours otherwise disable the form and allow only data view mode.

The function written for this task is given below can be copied to a Standard Module:

Public Function Data_Entry(ByVal frmName As String)
Dim T1S, T1E, T2S, T2E, T3S, T3E
Dim frm As Form

Set frm = Forms(frmName)

D = Date
T1S = TimeValue("06:00:00")
T1E = TimeValue("07:00:00")

T2S = TimeValue("11:00:00")
T2E = TimeValue("13:00:00")

T3S = TimeValue("17:00:00")
T3E = TimeValue("19:00:00")

Select Case time
      Case T1S To T1E, T2S To T2E, T3S To T3E
          With frm
            If .AllowAdditions = False Then
               .AllowAdditions = True
               .AllowEdits = True
               .lblMsg.Visible = False
'change .subFrmName to match the control (window) name of the sub-form
               .subFrmName.Enabled = True
            End If
          End With
          frm.Refresh
      Case Else
          With frm
            If .AllowAdditions = True Then
                .AllowAdditions = False
                .AllowEdits = False
                .lblMsg.Visible = True
 'change the next line to set focus on any field on the main form
                .EmployeeID.SetFocus
'change .subFrmName to match the control (window) name of the sub-form
                .subFrmName.Enabled = False
            End If
          End With
          frm.Refresh
End Select

Set frm = Nothing
End Function

NB: You must make changes wherever applicable to point the code to correct control names on your Form, which I have marked with comments.

  1. Open your Form in Design View.
  2. Add a Label Control on the main Form where you want to display 'Entry not allowed', change the Name property value to lblMsg and write the message in the Caption property.
  3. Display the Form Property Sheet.
  4. Set Timer Interval value to 60000 (i.e. 1 minute).  The Form’s current mode is checked in one minute interval apply changes automatically.  You may increase the time interval by adding 1000 to the above value for each second increase.
  5. Select On timer Event, select [Event Procedure] from the drop-down control and click on the build ( . . .) button to open the VBA module.
  6. Copy and Paste the following lines of Code replacing the existing two lines displayed there:

    Code:

    Private Sub Form_Timer()
       Data_Entry Me.Name
    End Sub
  7. Save and Close the Form.

The Timer setting will run the above program and will check every minute, whether the current time falls within the time slots given in the program, if true then the Main-form and a Sub-Form on the main form will be enabled for Editing/Entry purposes, otherwise they will be locked.

When you open the Form there will be a one minute delay before Access starts checking. You may call the Data_Entry() function from the Form_Current() event procedure to start checking immediately after opening to avoid the one minute initial delay.

Share:

No comments:

Post a Comment

Translate



PageRank
Subscribe in a reader
Your email address:

Delivered by FeedBurner

Search

Popular Posts

Search This Blog

Blog Archive

Powered by Blogger.

Labels

Forms How Tos Functions MS-Access Security Reports msaccess forms Animations msaccess animation Utilities msaccess controls Access and Internet MS-Access Scurity MS-Access and Internet Queries External Links msaccess reports msaccess tips Accesstips Array Menus and Toolbars MsaccessLinks Process Controls Art Work Downloads msaccess How Tos Graph Charts msaccessQuery Class Module List Boxes Property VBA Combo Boxes Command Buttons Data Emails and Alerts Objects Query Calculation Custom Wizards DOS Commands Data Type ms-access functions msaccess functions msaccess graphs msaccess reporttricks Collection Object msaccessprocess security advanced Access Security Custom Functions Field Type Form Macros Menus Object Reference Report Top Values Variables msaccess email msaccess menus progressmeter Access2007 Auto-Number Command Button Controls Copy Dictionary Object Expression Fields Form Instances Item Join Key Methods Microsoft Numbering System Records Recordset Security Split SubForm Table Time Difference Utility Workgroup Wrapper Classes database msaccess wizards tutorial Access2003 Accounting Year Action Add Animation Attachment Binary Numbers Bookmarks Budgeting ChDir Color Palette Conditional Formatting Data Filtering Defining Pages Diagram Disk Dynamic Lookup Error Handler Excel Export External Filter Formatting Groups Hexadecimal Numbers Import Labels List Logo Macro Mail Merge Main Form Memo Monitoring Octal Numbers Operating System Paste Primary-Key Product Rank Reading Remove Rich Text Sequence SetFocus Summary Tab-Page Tables Union Query User Users Water-Mark Word automatically commands function hyperlinks iSeries Date iif ms-access msaccess msaccess alerts pdf files reference restore switch text toolbar updating upload vba code

Featured Post

Sorting Dictionary Object Keys and Items

Sorting/Indexing of Table Records is a frequently used important exercise to organize the data in proper order, for faster retrieval of inf...

Labels

Blog Archive

Recent Posts