Home  |   French  |   About  |   Search  | mvps.org  

What's New
Table Of Contents
Credits
Netiquette
10 Commandments 
Bugs
Tables
Queries
Forms
Reports
Modules
APIs
Strings
Date/Time
General
Downloads
Resources
Search
Feedback
mvps.org

In Memoriam

Terms of Use


VB Petition

Forms: Fill Fields automatically on form based on a control's value

Author(s)
Erika Yoxall

(Q)    Is it possible to have some fields filled in automatically as soon as a certain value has been entered into another field?

(A)    A typical example of this is getting state and city name from Zipcodes. If you have a Zip-Code table, you'll never have to enter the State/City again. Add this simple code in the OnExit() event-handler for the field containing the Zipcode.

'************* Code Start **************
' This code was originally written by Erika Yoxall.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Erika Yoxall
'
Sub Zip_OnExit(Cancel As Integer)
Dim varState, varCity As Variant
    varState = DLookup("State", "tblZipCode", "ZipCode =[Zip] ")
    varCity = DLookup("City", "tblZipCode", "ZipCode =[Zip] ")
    If (Not IsNull(varState)) Then Me![State] = varState
    If (Not IsNull(varCity)) Then Me![City] = varCity
End Sub
'************* Code End **************

© 1998-2010, Dev Ashish & Arvin Meyer, All rights reserved. Optimized for Microsoft Internet Explorer