Group:  Microsoft Access ยป microsoft.public.access.modulesdaovba
Thread: Change field format programmatically

Geek News

Change field format programmatically
wAyne 2/2/2006 6:30:30 PM
Hi,

I have a table of items - where the item number display format is different
for based on item type.
e.g item type vertical item number ver-123 a b cc dd
item type piping itme number ver-4567890 a dd


Is ther a way I can alter the format so that when the record is dispayed it
display's the item number in the appropriate way?

Thanks
wAyne

Re: Change field format programmatically
Marshall Barton <marshbarton[ at ]wowway.com> 2/2/2006 11:06:18 PM
wAyne wrote:
[Quoted Text]
>I have a table of items - where the item number display format is different
>for based on item type.
>e.g item type vertical item number ver-123 a b cc dd
> item type piping itme number ver-4567890 a dd
>
>
>Is ther a way I can alter the format so that when the record is dispayed it
>display's the item number in the appropriate way?


If the form is displayed in Single View (not datasheet or
continuous), then you can use the form's Current event to
set the item number text box's Format property as needed.
Then general idea is something like:

Select Case Me.ItemType
Case "vertical"
Me.txtItemNumber.Format = "[ at ][ at ][ at ][ at ][ at ][ at ] [ at ] [ at ] [ at ][ at ] [ at ][ at ]"
Case "piping"
Me.txtItemNumber.Format = "[ at ][ at ][ at ][ at ][ at ][ at ][ at ][ at ][ at ][ at ][ at ] [ at ] [ at ][ at ]"
Case
. . .

--
Marsh
MVP [MS Access]
Re: Change field format programmatically
wAyne 2/3/2006 1:29:04 PM
Hi Marshall,

yeah, I thought of this -- but it is a continuous form -- is there asyway
to do this for continuous forms?

wAyne

"Marshall Barton" wrote:

[Quoted Text]
> wAyne wrote:
> >I have a table of items - where the item number display format is different
> >for based on item type.
> >e.g item type vertical item number ver-123 a b cc dd
> > item type piping itme number ver-4567890 a dd
> >
> >
> >Is ther a way I can alter the format so that when the record is dispayed it
> >display's the item number in the appropriate way?
>
>
> If the form is displayed in Single View (not datasheet or
> continuous), then you can use the form's Current event to
> set the item number text box's Format property as needed.
> Then general idea is something like:
>
> Select Case Me.ItemType
> Case "vertical"
> Me.txtItemNumber.Format = "[ at ][ at ][ at ][ at ][ at ][ at ] [ at ] [ at ] [ at ][ at ] [ at ][ at ]"
> Case "piping"
> Me.txtItemNumber.Format = "[ at ][ at ][ at ][ at ][ at ][ at ][ at ][ at ][ at ][ at ][ at ] [ at ] [ at ][ at ]"
> Case
> . . .
>
> --
> Marsh
> MVP [MS Access]
>
Re: Change field format programmatically
Marshall Barton <marshbarton[ at ]wowway.com> 2/3/2006 10:26:37 PM
In this case, things get kind of tricky.

Create a function in the form's module to format the value:

Private Function MyFormat(num, typ) As Variant
Select Case typ
Case "vertical"
MyFormat = Format(num, "[ at ][ at ][ at ][ at ][ at ][ at ] [ at ] [ at ] [ at ][ at ] [ at ][ at ]")
Case "piping"
MyFormat = Format(num, "[ at ][ at ][ at ][ at ][ at ][ at ][ at ][ at ][ at ][ at ][ at ] [ at ] [ at ][ at ]"
. . .
End Select
End Function

Create an text box to display the formatted value. Set its
control source expression to :
=MyFormat([item number], [item type])
and use its GotFocus event to immediately (re)set the focus
to the item number text box so the value can be edited.

Finally, size and position the display text box exactly on
top of the item number text box.
--
Marsh
MVP [MS Access]


wAyne wrote:
[Quoted Text]
>yeah, I thought of this -- but it is a continuous form -- is there asyway
>to do this for continuous forms?
>
>
>> wAyne wrote:
>> >I have a table of items - where the item number display format is different
>> >for based on item type.
>> >e.g item type vertical item number ver-123 a b cc dd
>> > item type piping itme number ver-4567890 a dd
>> >
>> >
>> >Is ther a way I can alter the format so that when the record is dispayed it
>> >display's the item number in the appropriate way?
>>
>
>"Marshall Barton" wrote:
>> If the form is displayed in Single View (not datasheet or
>> continuous), then you can use the form's Current event to
>> set the item number text box's Format property as needed.
>> Then general idea is something like:
>>
>> Select Case Me.ItemType
>> Case "vertical"
>> Me.txtItemNumber.Format = "[ at ][ at ][ at ][ at ][ at ][ at ] [ at ] [ at ] [ at ][ at ] [ at ][ at ]"
>> Case "piping"
>> Me.txtItemNumber.Format = "[ at ][ at ][ at ][ at ][ at ][ at ][ at ][ at ][ at ][ at ][ at ] [ at ] [ at ][ at ]"
>> Case
>> . . .
Re: Change field format programmatically
wAyne 2/7/2006 2:20:28 PM
Thanks Marsh,

Worked great ...

I di dmake one change -- instead of using a case statemtn - I placed the
formats in with the unit type table and used those -- allows for more
flexibility -- and right now they keep changing there minds on fomrats and
adding new types.

wAyne_

"Marshall Barton" wrote:

[Quoted Text]
> In this case, things get kind of tricky.
>
> Create a function in the form's module to format the value:
>
> Private Function MyFormat(num, typ) As Variant
> Select Case typ
> Case "vertical"
> MyFormat = Format(num, "[ at ][ at ][ at ][ at ][ at ][ at ] [ at ] [ at ] [ at ][ at ] [ at ][ at ]")
> Case "piping"
> MyFormat = Format(num, "[ at ][ at ][ at ][ at ][ at ][ at ][ at ][ at ][ at ][ at ][ at ] [ at ] [ at ][ at ]"
> . . .
> End Select
> End Function
>
> Create an text box to display the formatted value. Set its
> control source expression to :
> =MyFormat([item number], [item type])
> and use its GotFocus event to immediately (re)set the focus
> to the item number text box so the value can be edited.
>
> Finally, size and position the display text box exactly on
> top of the item number text box.
> --
> Marsh
> MVP [MS Access]
>
>
> wAyne wrote:
> >yeah, I thought of this -- but it is a continuous form -- is there asyway
> >to do this for continuous forms?
> >
> >
> >> wAyne wrote:
> >> >I have a table of items - where the item number display format is different
> >> >for based on item type.
> >> >e.g item type vertical item number ver-123 a b cc dd
> >> > item type piping itme number ver-4567890 a dd
> >> >
> >> >
> >> >Is ther a way I can alter the format so that when the record is dispayed it
> >> >display's the item number in the appropriate way?
> >>
> >
> >"Marshall Barton" wrote:
> >> If the form is displayed in Single View (not datasheet or
> >> continuous), then you can use the form's Current event to
> >> set the item number text box's Format property as needed.
> >> Then general idea is something like:
> >>
> >> Select Case Me.ItemType
> >> Case "vertical"
> >> Me.txtItemNumber.Format = "[ at ][ at ][ at ][ at ][ at ][ at ] [ at ] [ at ] [ at ][ at ] [ at ][ at ]"
> >> Case "piping"
> >> Me.txtItemNumber.Format = "[ at ][ at ][ at ][ at ][ at ][ at ][ at ][ at ][ at ][ at ][ at ] [ at ] [ at ][ at ]"
> >> Case
> >> . . .
>
Re: Change field format programmatically
Marshall Barton <marshbarton[ at ]wowway.com> 2/7/2006 4:05:17 PM
Good generalization. Any time you can put stuff in a table
(where users can edit via a form) instead of code (where you
have to program and distribute the changes), you are way,
way better off. Just make sure the function's logic guards
against all kinds of user mistakes ;-)
--
Marsh
MVP [MS Access]



wAyne wrote:
[Quoted Text]
>Worked great ...
>
>I di dmake one change -- instead of using a case statemtn - I placed the
>formats in with the unit type table and used those -- allows for more
>flexibility -- and right now they keep changing there minds on fomrats and
>adding new types.
>
>
>"Marshall Barton" wrote:
>> In this case, things get kind of tricky.
>>
>> Create a function in the form's module to format the value:
>>
>> Private Function MyFormat(num, typ) As Variant
>> Select Case typ
>> Case "vertical"
>> MyFormat = Format(num, "[ at ][ at ][ at ][ at ][ at ][ at ] [ at ] [ at ] [ at ][ at ] [ at ][ at ]")
>> Case "piping"
>> MyFormat = Format(num, "[ at ][ at ][ at ][ at ][ at ][ at ][ at ][ at ][ at ][ at ][ at ] [ at ] [ at ][ at ]"
>> . . .
>> End Select
>> End Function
>>
>> Create an text box to display the formatted value. Set its
>> control source expression to :
>> =MyFormat([item number], [item type])
>> and use its GotFocus event to immediately (re)set the focus
>> to the item number text box so the value can be edited.
>>
>> Finally, size and position the display text box exactly on
>> top of the item number text box.
>>
>>
>> wAyne wrote:
>> >yeah, I thought of this -- but it is a continuous form -- is there asyway
>> >to do this for continuous forms?
>> >
>> >
>> >> wAyne wrote:
>> >> >I have a table of items - where the item number display format is different
>> >> >for based on item type.
>> >> >e.g item type vertical item number ver-123 a b cc dd
>> >> > item type piping itme number ver-4567890 a dd
>> >> >
>> >> >
>> >> >Is ther a way I can alter the format so that when the record is dispayed it
>> >> >display's the item number in the appropriate way?
>> >>
>> >
>> >"Marshall Barton" wrote:
>> >> If the form is displayed in Single View (not datasheet or
>> >> continuous), then you can use the form's Current event to
>> >> set the item number text box's Format property as needed.
>> >> Then general idea is something like:
>> >>
>> >> Select Case Me.ItemType
>> >> Case "vertical"
>> >> Me.txtItemNumber.Format = "[ at ][ at ][ at ][ at ][ at ][ at ] [ at ] [ at ] [ at ][ at ] [ at ][ at ]"
>> >> Case "piping"
>> >> Me.txtItemNumber.Format = "[ at ][ at ][ at ][ at ][ at ][ at ][ at ][ at ][ at ][ at ][ at ] [ at ] [ at ][ at ]"
>> >> Case
>> >> . . .
>>

Re: Change field format programmatically
punitha 12/31/2008 6:47:01 AM
hi wayne,

i'm having the same prob too. i tried the case statement as marsh suggested.
it works well half way thru. but when i add new record the format gets
defaulted to "[ at ][ at ][ at ][ at ][ at ][ at ]-[ at ][ at ]-[ at ][ at ][ at ][ at ]".

here's what i'm using:

Private Sub Form_Current()
Select Case Me.cboIdType
Case "IC"
Me.txtPtID.Format = "[ at ][ at ][ at ][ at ][ at ][ at ]-[ at ][ at ]-[ at ][ at ][ at ][ at ]"
Case "BC"
Me.txtPtID.Format = "[ at ][ at ] [ at ][ at ][ at ][ at ][ at ][ at ]"
End Select
End Sub

appreciate ur help.
tq


"wAyne" wrote:

[Quoted Text]
> Thanks Marsh,
>
> Worked great ...
>
> I di dmake one change -- instead of using a case statemtn - I placed the
> formats in with the unit type table and used those -- allows for more
> flexibility -- and right now they keep changing there minds on fomrats and
> adding new types.
>
> wAyne_
>
> "Marshall Barton" wrote:
>
> > In this case, things get kind of tricky.
> >
> > Create a function in the form's module to format the value:
> >
> > Private Function MyFormat(num, typ) As Variant
> > Select Case typ
> > Case "vertical"
> > MyFormat = Format(num, "[ at ][ at ][ at ][ at ][ at ][ at ] [ at ] [ at ] [ at ][ at ] [ at ][ at ]")
> > Case "piping"
> > MyFormat = Format(num, "[ at ][ at ][ at ][ at ][ at ][ at ][ at ][ at ][ at ][ at ][ at ] [ at ] [ at ][ at ]"
> > . . .
> > End Select
> > End Function
> >
> > Create an text box to display the formatted value. Set its
> > control source expression to :
> > =MyFormat([item number], [item type])
> > and use its GotFocus event to immediately (re)set the focus
> > to the item number text box so the value can be edited.
> >
> > Finally, size and position the display text box exactly on
> > top of the item number text box.
> > --
> > Marsh
> > MVP [MS Access]
> >
> >
> > wAyne wrote:
> > >yeah, I thought of this -- but it is a continuous form -- is there asyway
> > >to do this for continuous forms?
> > >
> > >
> > >> wAyne wrote:
> > >> >I have a table of items - where the item number display format is different
> > >> >for based on item type.
> > >> >e.g item type vertical item number ver-123 a b cc dd
> > >> > item type piping itme number ver-4567890 a dd
> > >> >
> > >> >
> > >> >Is ther a way I can alter the format so that when the record is dispayed it
> > >> >display's the item number in the appropriate way?
> > >>
> > >
> > >"Marshall Barton" wrote:
> > >> If the form is displayed in Single View (not datasheet or
> > >> continuous), then you can use the form's Current event to
> > >> set the item number text box's Format property as needed.
> > >> Then general idea is something like:
> > >>
> > >> Select Case Me.ItemType
> > >> Case "vertical"
> > >> Me.txtItemNumber.Format = "[ at ][ at ][ at ][ at ][ at ][ at ] [ at ] [ at ] [ at ][ at ] [ at ][ at ]"
> > >> Case "piping"
> > >> Me.txtItemNumber.Format = "[ at ][ at ][ at ][ at ][ at ][ at ][ at ][ at ][ at ][ at ][ at ] [ at ] [ at ][ at ]"
> > >> Case
> > >> . . .
> >

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net