×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Wierd Mid() behaviour

Wierd Mid() behaviour

Wierd Mid() behaviour

(OP)
Hi Folks

Got a report and in it I have 25 Text fields named txtName1 .... to ... txtName25. the fields were setup and then copied and pasted then the name changed.

I'm using the following to seperate out each char in the pet's name (me!PetName) and put it into each of the text fields (i.e. 1 char per field)

CODE --> VBA

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim vcounter As Variant
Dim tmpltr As String

    vcounter = 1
    If Me!PetName <> "" Or Not IsNull(Me!PetName) Then
        For Each ctrl In Me.Controls
            If ctrl.Name = "txtName" & vcounter Then
                tmpltr = Mid(Trim(Me!PetName), vcounter, 1)
                ctrl.Value = StrConv(tmpltr, 1)
                vcounter = vcounter + 1
                tmpltr = ""
            End If
        Next
    End If
End Sub 

However when the vcounter value gets to 8, it won't +1 and resets back to 1. I've changed to vcounter to integer type and it does not make any different.

If I start the vcounter at 9 it works fine from there. I've deleted the field and recreated it and again no change. If I start vcounter from 5 it only goes to 8. If I start vcounter at 8 it only does the 8th one and resets back to 1.

This is so bazaar. Anyone possibly have an idea whats going on.

I'm off to open another bottle of wine.

RE: Wierd Mid() behaviour

I would rather loop with: For i=1 To Len(Trim(Me!PetName)) and refer to control named "txtName" & i.
In your code For Each uses internal order of controls, you increase vcounter if name match template and next you increase vcounter. It's a bit random.

combo

RE: Wierd Mid() behaviour

>I'm using the following to seperate out each char in the pet's name (me!PetName) and put it into each of the text fields (i.e. 1 char per field)
No, you don't
You take only first character from txtName1, only second character from txtName2, third character from txtName3, and so on.


---- Andy

There is a great need for a sarcasm font.

RE: Wierd Mid() behaviour

(OP)
Hi guys

Yes combo I could limit it to the name length and will look at that

Andrzejek, isn't that the reverse of what I trying yo do. Fields txtName1, txName2 etc are empty fields at report open until I put something in them.

All I doing (or trying to do) is to take 1 letter (char) at a time from a pet's name and put it into a seperate field.

This is what happens if I set vcounter to 1



This is what happens if I set it to 8






RE: Wierd Mid() behaviour

(OP)
And this is what happens if I set vcounter to 9

RE: Wierd Mid() behaviour

(OP)
All sorted thanks guys.

It turned out to be the TAB Stop positions and even with all others tab stop turned off it still didn't work.

So... I've hard codes each field to get around the problem.

txtName1 = Mid(Trim(Me!PetName), 1, 1)
txtName2 = Mid(Trim(Me!PetName), 2, 1)

etc..

So thanks guys for responding.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close