In this video I talk about how to program vba object items like the ms access form.
Specifically we look at the Access Form Open Event, and add a password prompt in the open event of the form, cancelling the open event if it is incorrect.
Also we will look at controlling the Form_Load with a public variable and the Form_Current event.
The possibilities for the Form_Current event procedure.
-diplay a message box
-display data in the caption of the form.
-display the customer’s previous order
-display all the books by the publisher (based on publisher id)
-perform form level calculation on form data
Remember:
The Current Event happens before the Load Event.
Option Compare Database Option Explicit Public strUser As String Private Sub Form_Current() 'possibilities for the current record. 'diplay a message box 'display data in the caption of the form. 'display the customer's previous order 'display all the books by the publisher (based on publisher id) 'perform form level calculation on form data 'Caption If Len(Me.txtTitle) Then Forms!frmFormEvents.Caption = txtTitle.Value End If End Sub Private Sub Form_Load() MsgBox "Welcome, " & strUser End Sub Private Sub Form_Open(Cancel As Integer) 'happens before the load event Dim strPassword As String strUser = InputBox("Enter The User") strPassword = InputBox("Enter The Password") If strPassword <> "Password" Then MsgBox "Incorrect Password" Cancel = True End If End Sub
<< VBA Form Object Event Procedures | MS Access Form Events – PT2 >>
Learn Access VBA: Understand Tables, Queries, Forms, and Reports
Learn Access VBA: From Zero to Database Hero If you’ve ever opened Microsoft Access and wondered how all the pieces fit together — tables, queries, forms, and reports — this tutorial is made for you. In just a few minutes, you’ll understand how Access works behind the scenes and see how VBA (Visual Basic for […]
How To Make An Access Form Time Picker
Here is a relatively easy way to select times for your time entry text boxes. It’s a reusable form that allows you to pick a time from an Access form. There are probably different ways to do this but here is the way I would do it. On the form that has the time fields, […]
How to pick a file to load In VBA
How to Pick a File in VBA: FileDialog & GetOpenFilename Explained When building Excel VBA applications, you’ll often need to let users pick a file to load in VBA. Instead of hard-coding file paths, you can use built-in dialogs that make file selection easy and user-friendly. VBA offers two main approaches: FileDialog object (flexible, customizable) […]
What is the purpose of the Me keyword in Access VBA?
What does the Me keyword mean? “Me” refers to the Access form currently in focus. Instead of writing out the entire form reference, you can just use the keyword “Me” which is easier. Like: Me.txtbox = “I am a textbox on the form that currently has the focus.” or you can update a label’s caption […]
Support these sponsors: