SirMegaton
New member
- Local time
- Yesterday, 21:03
- Joined
- Dec 13, 2015
- Messages
- 4
Hello, I'm having trouble understanding how to autocomplete something using VBA Form_BeforeUpdate.
This is a practice exam I took a few days ago, and I still don't understand this piece. The example my Professor gave is to pretend that I was told that the Zip field for Meriden have changed from 10050 to 10050-0050. So I want to create a function procedure so that if I type in Zip 10050 that the Form File I'm using will automatically update that record to 10050-0050, and that the underlying table will be updated when form records are updated as well.
The book I am using for this course only shows one example with BeforeUpdate, and it doesn't relate to this.
This is how I thought it should be but it doesn't automatically change the Zip 10050 to 10050-0050.
Code:
Anything to help understand this would be great. Thanks.
This is a practice exam I took a few days ago, and I still don't understand this piece. The example my Professor gave is to pretend that I was told that the Zip field for Meriden have changed from 10050 to 10050-0050. So I want to create a function procedure so that if I type in Zip 10050 that the Form File I'm using will automatically update that record to 10050-0050, and that the underlying table will be updated when form records are updated as well.
The book I am using for this course only shows one example with BeforeUpdate, and it doesn't relate to this.
This is how I thought it should be but it doesn't automatically change the Zip 10050 to 10050-0050.
Code:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim Zip As String
If Not IsNull([City]) And Not IsNull([Zip]) Then
Zip = Left([Zip], 5)
Select Case [City]
Case "Meriden"
If Zip = "10050" Then
Zip = "10050-0050"
End If
End Select
End If
End Sub
Anything to help understand this would be great. Thanks.