Actually, I would make the code a little more generic to allow specifying any text to stick between letters:
Public Function TxtNumSpaced(n As String, Optional strInsert As String = " ") As String
' Add a string between each characater of String.
Dim i As Integer
Dim s As String
On Error GoTo MyErr
For i = 1 To Len(n)
s = s & Mid$(n, i, 1) & strInsert
Next i
TxtNumSpaced = Left(s, Len(s) - Len(strInsert))
MyExit:
Exit Function
MyErr:
MsgBox "Err =" & Err & vbCrLf & Err.Description
Resume MyExit
End Function
You would not use code. Your control source would use:
=TxtNumSpaced([YourFieldNameHere])
Duane Hookom
MS Access MVP
--- In MS_Access_Professionals@yahoogroups.com, Agestha Hendra <agesthahendra@...> wrote:
>
> thanx Clive...
> How should i use this code ? i have a textbox named txtSpace in a report (rptIDCard) and i want to display
> the results of the code that you have given to the txtSpace...sorry... i'm newbie in VBA.
> I have maked a new module and paste the code, and then on open event of rptIDCard i have typed theese :
>
> Call TxtNumSpaced
> Me.txtSpace=TxtNumSpaced
>
> it gived erorr when i tried to open the report,,,
>
> Regards
> Hendra
>
>
>
> ________________________________
> Dari: Clive <zctek@...>
> Kepada: MS_Access_Professionals@yahoogroups.com
> Dikirim: Jumat, 2 Maret 2012 16:51
> Judul: [MS_AccessPros] Re: Give space between chracters in a field
>
>
> Â
> Hi Hendra,
>
> You could do it with a Function like;
>
> Public Function TxtNumSpaced(n As String) As String
> ' Add a space between each characater of String.
> Dim i As Integer
> Dim s As String
> On Error GoTo MyErr
> For i = 1 To Len(n)
> s = s & Mid$(n, i, 1) & " "
> Next i
> TxtNumSpaced = Trim(s)
> MyExit:
> Exit Function
> MyErr:
> MsgBox "Err =" & Err & vbCrLf & Err.Description
> Resume MyExit
> End Function
>
> Regards, Clive.
>
> --- In MS_Access_Professionals@yahoogroups.com, "agesthahendra@" <agesthahendra@> wrote:
> >
> > Hi Everyone..
> >
> > How can we give space between characters in the value of a field..?
> > For example i have a field (Text type) with value = 12345, i want to
> > give space between the characters to be 1 2 3 4 5 and display it on
> > a report or form...
> > Any directions would be appreciated...thank you
> >
> > Regards
> > Hendra
> >
>
>
>
>
> [Non-text portions of this message have been removed]
>
Jumat, 02 Maret 2012
Bls: [MS_AccessPros] Re: Give space between chracters in a field
__._,_.___
.
__,_._,___
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar