Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2009
    Posts
    49

    Unanswered: Label's First Line

    Hi,

    I thought my troubles with labels were finally behind me, but this one decided to rear it's ugly head.

    I have a label with a caption of 2 concatenated lines (Line1 & vbCrLf & Line2)

    The caption was defined by an earlier piece of coding. I want to have a query that looks up a record on a table with the criteria of the label caption's first line.

    Unfortunately I can't seem to find a way to only use "Line 1" in the query. I was using a textbox as an itermediary between the selection of the label and the query...

    Selected label... Caption copied into TxtBox... Run query based on TxtBox

    So at the moment TxtBox is a 2-line value, but I only want the first Line.

    Edit: Also I can't assign "Line1" to the Label.name as the name is very important in the other coding.

    Thanks
    Phil
    Last edited by pb190; 12-08-09 at 07:31. Reason: Missed a bit

  2. #2
    Join Date
    Nov 2009
    Posts
    49
    Sorry guys,

    Was being stupid and had the right coding, but was outputing to the wrong txtBox lol. But will post answer anyway

    Dim carriage As String

    carriage = vbCrLf
    SessionNamebox.Value = Mid(Session1.Caption, 1, InStr(1, Session1.Caption, carriage)-1)


    Mid() is the method to return a value of a certain length. So Session1.caption is the string that is to be essentially cropped. 1 is the starting position and the rest is the end value. As the end value varies depending on where the carriage return is the following piece of coding finds that last value.

    InStr() is looking for a string within a string returning the position value of the first occurance. So Session1.caption is the main string, carriage is the Carriage Return key (String 2) and the 1 means start from position 1.

    Hope this makes sense
    Thanks
    Phil
    Last edited by pb190; 12-09-09 at 07:21.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •