using Mid function

Sam Summers

Registered User.
Local time
Today, 04:24
Joined
Sep 17, 2001
Messages
939
Hi Guys,

This one Is new to me:

I have a combobox "ClientName" and a textbox "ReportNo" on a form.

When the user selects a client from "ClientName" I want to display the first two letters of the Clients name as capital letters in the "ReportNo" Textbox which will be used to create a concatenated report number in another Textbox.

At the moment nothing seems to happen when using the code below?
I have tried the same in the after Update Event but that doesn't work either?

Many thanks once again!

Code:
Private Sub Client_Name_Change()

Me.ReportNo.SetFocus
Me.ReportNo.Value = Mid([Client Name], 2)

End Sub

[\CODE]
 
Well, I managed to solve it myself-

I had the focus set to the wrong control and also a slight tweek of the code as below so it now works

Code:
Private Sub Client_Name_Change()

Me.Client_Name.SetFocus
Me.ReportNo.Value = Mid([Client Name].Text, 1, 3)

End Sub
 
As originally written, it would have stated at the 3rd position and included the remaining string - but you knew that already!
 
note

mid(string,1,3) will select 3 chars rather than 2, starting at position 1.

you could simply use left.

left(string,3)

and you can capitalise it with ucase

ucase(left(string,3))

in the unlikely event you have leading spaces, you could also get rid of those, if you wanted with either

trim() or ltrim()

ucase(left(ltrim(string),3))
 

Users who are viewing this thread

Back
Top Bottom