Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Event Procedure causes user-defined type not defined 2

Status
Not open for further replies.

rbwsr

Technical User
Jun 21, 2001
2
US
I'm trying to write a procedure that will allow a user to input his zipcode and the City and State will automatically be updated.

I'm using unbound text to trigger the event procedure. Here is the code:

Private Sub ZipCode_AfterUpdate()
'This Sub looks up a zipcode in the table named
'ZipCodes and, if it finds a matching zipcode, fills in
'the City and State controls from data
'in the ZipCodes table.

'Declare DAO object variables and string variable.
Dim ThisDB As Database
Dim ZipCodes As Recordset
Dim LookFor As String

'Define DAO object variables
Set ThisDB = CurrentDb()
Set ZipCodes = ThisDB.OpenRecordset("ZipCodes")

'Isolate the first five characters in the ZipCode field.
LookFor = Left([ZipCode], 5)

'Define the index to search, then seek the LookFor value
ZipCodes.Index = "PrimaryKey"
ZipCodes.Seek "=", LookFor

'If not found, beep and move focus to the City control
If ZipCodes.NoMatch Then
DoCmd.Beep
DoCmd.GoToControl "City"
Else
'If a matching zipcode is found, fill City and State
'fields then move to the CompanyName control.
[City] = ZipCodes!City
[State] = ZipCodes!State
DoCmd.GoToControl "CompanyName"
End If

End Sub
 
In a code window goto tools, references and make sure that you have DAO 3.6? checked. Can't think what else it can be.
 
Thanks for the tip. That fixed the problem
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top