Enable and disable Microsoft Access Form control using VBA


Time bound form made change using VBA

This article is basically making a Microsoft Access Form enable or disable on particular time period. Within specific time period we can use the Access Form otherwise the Form is disable for other times periods. It is interesting MS Access technique to enabling or disabling Form for Time periods.

For implementation of this technique in our article we have to first create a table as shown in Fig 1.1.

Enable and disable Microsoft Access Form control using VBA Fig-1.1

Fig:-1.1

Next we have to select the Form design from Ribbon. Then we have to insert textbox as shown in Fig 1.2. Then we have to write the function for enabling or disabling the form for particular time period and on Form on timer event we have to call the function.

Enable and disable Microsoft Access Form control using VBA Fig-1.2

Fig:-1.2

After coding we have to test the Form in Form view. In coding part we are decided that on what time the Form is enabled or not. Fig 1.3 shows that the current Form is enabled. The Form is within Time period and we can make changes on this Form.

Enable and disable Microsoft Access Form control using VBA Fig-1.3

Fig:-1.3

This second case when Form is not between time periods. Fig 1.4 shows that the currently Form is disable.

Enable and disable Microsoft Access Form control using VBA Fig-1.4

Fig:-1.4

VBA CODE

'Call the function
Option Compare Database
Private Sub Form_Timer()
timeform Me.Name
End Sub

'VBA code on Function
Option Compare Database
Public Function timeForm(ByVal frmName As String)
Dim T1, T2
Dim frm As Form
Set frm = Forms(Form1)
T1 = CDate(Date & " " & TimeValue("01:00:00"))
T2 = CDate(Date & " " & TimeValue("02:00:00"))
If ((Now() >= T1) And (Now() <= T2)) Then
With frm
MsgBox ("form enabled")
.AllowAdditions = True
.AllowEdits = True
End With
frm.Refresh
Else
With frm
MsgBox ("form disable")
.AllowAdditions = False
.AllowEdits = False
'.lblMsg.Visible = True
End With
frm.Refresh
End If
Set frm = Nothing
End Function


DISCLAIMER

It is advised that the information provided in the article should not be used for any kind formal or production programming purposes as content of the article may not be complete or well tested. ERP Makers will not be responsible for any kind of damage (monetary, time, personal or any other type) which may take place because of the usage of the content in the article.


 

BUY SERVICES CONTACT