Jumat, 06 April 2012

[MS_AccessPros] Re: Hard coding a character return in MS Access 2003 Query

 

Hi John,

Bill beat me to the punch!

I wrote some VBA to do the job. It handles errors too
so has some advantage. Here it is if you wnat it.

Public Function SplitForJohnF(pStr As String, Optional pChar As String = "/") As String
' Split a string like "abc/def" into "abc" & vbcrlf & "def"
' Option: A different value for pChar can be specified.
Dim idx As Integer
If InStr(pStr, pChar) = 0 Then
' Return an error string here.
SplitForJohnF = "No '" & pChar & "' found."
Exit Function
End If
idx = InStr(pStr, pChar)
SplitForJohnF = Left$(pStr, idx - 1) & vbCrLf & Mid$(pStr, idx + 1)
MyExit:
Exit Function
MyErr:
MsgBox "Err=" & Err & vbCrLf & Err.Description
Resume MyExit
End Function

In the Query use: DisplayedName: SplitForJohnF([Fieldname])

Regards, Clive.

--- In MS_Access_Professionals@yahoogroups.com, "Bill Mosca" <wrmosca@...> wrote:
>
> John
>
> The first piece: Left([MyField],instr([MyField],"/"))
>
> Second piece: Mid([MyField],instr([MyField],"/")+1)
>
> Regards,
> Bill Mosca, Founder - MS_Access_Professionals
> http://www.thatlldoit.com
> Microsoft Office Access MVP
> https://mvp.support.microsoft.com/profile/Bill.Mosca
>
>
>
> --- In MS_Access_Professionals@yahoogroups.com, "jfakes.rm" <jfakes@> wrote:
> >
> > I have a feild that a user now wants to split into two different fields in a report. I don't have the option of using two different fields in a table as it is one field.
> >
> > For example 12345/67899 needs to look like:
> > 12345/
> > 67899
> >
> > The lengths of the fields can vary for example I could have 1/3, or 12/123, or 1/ (yes thats a blank or null), and there might not be anything in the field at all.
> >
> > In a query, how can I code a hard return after the "/", taking into account that there might not be a fraction (null) in the field.
> >
> > Thanks in advance,
> > John F
> >
>

__._,_.___
.

__,_._,___

Tidak ada komentar:

Posting Komentar