Home  Fees/Services  Access Examples  Tutorials  Access Download  Articles  Search  Contact  Privacy  Links

Access Form Programming Tutorial

 



Form Programming Home


Unbound Forms in Microsoft Access

Access Unbound Forms for Data Control & Validation

Unbound Forms are used by our programmers occasionally to create a form with some many field validations and user movement control and coordination.  Bound forms can make fine control difficult when controlling field navigation. Access will often take control and attempt to save the record before you want it to be saved.

Below is the setup of the unbound form in design view:

Unbound Forms Programming Examples


The Save Customer button has about 10 screens of VBA code that validates almost every field on the unbound form for one condition or another.

There are also after update events on many fields in our unbound form example used to catch errors as the data is being entered.  Below is just a snippet of the VBA code to handle the CC Type versus the CC Number fields:

Select Case Me.CC_Type_Combo
Case 1
'amex
    If IsNull(Me.CC_Number) = True Then
        MsgBox "You must enter an AMEX number."
        Me.CC_Number.SetFocus
        Exit Sub
    End If
    If Len(Me.CC_Number) <> 15 Then
        MsgBox "The credit card number should have 15 digits."
        Me.CC_Number.SetFocus
        Exit Sub
    End If
    If Left(Me.CC_Number, 1) <> "3" Then
        MsgBox "AmEx numbers must start with a 3."
        Me.CC_Number.SetFocus
        Exit Sub
    End If
Case 3
    If IsNull(Me.CC_Number) = True Then
        MsgBox "You must enter an Visa number."
        Me.CC_Number.SetFocus
        Exit Sub
        End If
    If Left(Me.CC_Number, 1) <> "4" Then
        MsgBox "Visa card numbers must start with a 4."
        Me.CC_Number.SetFocus
        Exit Sub
    End If
    If Len(Me.CC_Number) <> 16 Then
        MsgBox "This card type should have a 16 digit number."
        Me.CC_Number.SetFocus
        Exit Sub
    End If
Case 2
.
.
.
After each field has been validated we can save the record with the Save Record button.  Here is the main part of the code that saves the data to the table... note that Dim statements are missing here:

Set db = CurrentDb
Set rst = db.OpenRecordset("M_Customers")
With rst
    .AddNew
    !Name_Prefix_ID = Me.Prefix_Combo
    !First_Name = Me.First_Name
    !Last_Name = Me.Last_Name
    !Address1 = Me.Address1
    !Address2 = Me.Address2
    !City = Me.City
    !State = Me.State
    !Zip = Me.Zip
    !Main_Phone = Me.Main_Phone
    !Cell_Phone = Me.Cell_Phone
    !Fax_Phone = Me.Fax_Phone
    !E_Mail = Me.E_Mail
    !CC_Type = Me.CC_Type_Combo
    !CC_Number = Me.CC_Number
    !CC_Exp = Me.CC_Exp
    .Update
End With
rst.Close
 

And lastly here is the unbound form in run view:

Access Unbound Form











A Blue Claw Database Design Template:

Work Order Administration Software
 








A Blue Claw Database Design Article:

Learn How To Select A Consultant
 




Contact Information

Copyright 2000-2012 Blue Claw Database Design, LLC