Prev: Global variables - again - sorry
Next: Command Button to open a password protected excel spreadsheet
From: Mike Painter on 22 Feb 2010 13:23 Irshad Alam wrote: > Dear Sir, > > I tried the code below as advised, > > Private Sub Model_AfterUpdate() > If right(Me.Model, 3) = "llc" Then UCase (right(Me.Model, 3)) > End Sub > Try it in a beforeupdate event.
From: John W. Vinson on 22 Feb 2010 16:14 On Mon, 22 Feb 2010 10:23:33 -0800, "Mike Painter" <md.painter(a)sbcglobal.net> wrote: >Irshad Alam wrote: >> Dear Sir, >> >> I tried the code below as advised, >> >> Private Sub Model_AfterUpdate() >> If right(Me.Model, 3) = "llc" Then UCase (right(Me.Model, 3)) >> End Sub >> >Try it in a beforeupdate event. > Actually, somewhat confusingly, the AfterUpdate event is correct. Changing the value of a control in that control's BeforeUpdate event will cause the BeforeUpdate event to fire *again*, giving (in this case) an endless loop. The problem is that Irshad is assuming that UCase means "do something to this value" - it doesn't, it simply returns a variable consisting of the changed-case version of its argument. He's not setting anything TO that value. Just in case, the proper code (well, one of many ways to do this) would be If Right(Me!Model, 3) = "llc" Then Me!Model = Left(Me!Model), Len(Me!Model) - 3)) & "LLC" End If -- John W. Vinson [MVP]
From: Irshad Alam on 22 Feb 2010 23:46 Dear Sir, Thank you, I implemented and it worked perfect. Regards Irshad "John W. Vinson" wrote: > On Sun, 21 Feb 2010 22:37:01 -0800, Irshad Alam > <IrshadAlam(a)discussions.microsoft.com> wrote: > > >I have field on the form named Model, in which I want to change last 3 > >alphabet to capital, generall the data entry is like below : > > > >wa470 llc > >wa420 > >3bc > > > >So, I tried to apply the below, which gives no result (no error or show no > >change) > > > > > >Private Sub Model_AfterUpdate() > >Dim last3 As String > >last3 = right(Me.Model, 3) > >If right(Me.Model, 3) = "llc" Then > >UCase (last3) > >End If > >End Sub > > > >Please advice > > > >Regards > > > >Irshad > > You're misunderstanding how UCase() works. It doesn't change anything in your > form or in your table; it is just a function that returns a value. Try typing > Ctrl-G and type: > > ?Ucase("llc") > > in the Immediate window and you'll see. > > To change the value in the textbox, you must explicitly set the textbox to an > expression, e.g. > > Private Sub Model_AfterUpdate() > If Right(Me!Model, 3) = "llc" Then > Me!Model = Left(Me!Model, Len(Me!Model) - 3) & "LLC" > End If > End Sub > > -- > > John W. Vinson [MVP] > . >
First
|
Prev
|
Pages: 1 2 Prev: Global variables - again - sorry Next: Command Button to open a password protected excel spreadsheet |