<%dim crumb,crumb1 crumb="Unbound Forms" crumb1="Unbound Data Entry Forms" %> Unbound Forms in Access
Home  Fees/Services  Access Examples  Tutorials  Access Download  Articles  Search  Contact  Privacy  Links

Access Form Programming Tutorial
<% response.write crumb1 %>

Home > Microsoft Access Tutorials > Access Forms Tutorial <% response.write ">" & crumb %>
<% Gnum="9096031968" Ynum="7841" dim Page_Type Page_Type="Prog" response.write "" %>






Form Subtotal Fields
Master/Detail Forms
NotInList Event
Speed Up Forms
Unbound Form
Change Textbox Height
Get Website Data
Access Audit Trail

Form Query Parameter



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 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. We recommend that you don't use unbound forms since they require a lot of additional programming.

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





















Microsoft Office Forms:
 MS Access 2003
 Access 2007
 Access 2010
 Access 2013




Contact Information

<% Response.write "Copyright 2000-" & year(now) & " Blue Claw Database Design" %>