Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Generically referencing form fileds

Status
Not open for further replies.

GBall

Programmer
May 23, 2001
193
GB
Hi,
I have to process a number of controls and I want to have the code defined just once.
So I have this piece of code. Problem is, I get 'invalid use of null on the 'Len' statement.
If I replace it with say 50, the code works fine.
I tried this out in access 2000 using len(me!text0) (text0 being the actual field name), but when I tried it in 97 (in order to try and find the error), that wouldn't work either !!
This should be so simple - it's driving me nuts.



Private Sub Process_MouseMove(ctl_name)
Dim txtname As String
Dim i As Integer
Dim x As Long

txtname = "txt" & mID(ctl_name, 4)

Me(txtname).SetFocus
Me(txtname).SelStart = 0
Me(txtname).SelLength = 0
For i = 1 To Len(Me(txtname))
Me(txtname).SelStart = Me(txtname).SelStart + 1
For x = 1 To 750000
Next x
Next

End Sub

If you're wondering what the code is trying to achieve - it's a scrolling textbox.
thanks.



Regards,
Graham
 
Graham

Check for null or zero length srring...

Code:
[COLOR=blue]
If Len(Nz(Me.txtname, "")) Then [/color]
    For i = 1 To Len(Me(txtname))
         Me(txtname).SelStart = Me(txtname).SelStart + 1
         For x = 1 To 750000
         Next x
    Next
[COLOR=blue]End If [/color]

Richard
 
That's a good point, but the textbox actually does have data in it.

Regards,
Graham
 
w/o regard to your real issue, I would suggest that the 'idle loop' be replaced with a timer, The current version will 'lock up' the system for ther duration of the loop, while a timer driven process would permit other activities, possibly including stopping, restarting or rr directing the scroll.

RE the 'real' issue, your code 'assumes' a three character prefix for control names. If you have misnamed a control and the results of the concatenation do NOT result in the (valid) name of a control you will get the error. Try placing a breakpoint on the line and getting the concatenation operation results to see what you are actually refering to. "De-Bug" would be usable to investigate proprties of the control.





MichaelRed
mlred@verizon.net

 
Thanks Michael.
I am planning to use a timer; this is just proof of concept.
Actually, the user has no control over the scrolling anyway.
I have debbugged the code and the field name is correct.
There is only one(at the moment) and I named it.

I assume then that there is nothing wrong with the code and it should pick up the length of the field using that syntax.

Regards,
Graham
 
As a "Concept", it works. I can get a memo field in a text box to scroll by simply passing the full, correct control name to the procedure and setting [txtName] directly to that (w/o replacing the first three chars of the control name w/ "txt"). It does, however -even in the simplistic mode leave a lot to be desired:

[tab]The scrolling is 'jerky'.
[tab]The loop continues for its' "own" length regardless of the size (length" of the content.
[tab]The speed of the scroll is not convienient to peruse the content.
[tab] ...


but as a concept, it works (if you do NOT monkey w. the control NAME)!

(((WQhich somewhat baffles be as to what / why you would do so ... ))





MichaelRed
mlred@verizon.net

 
Yes, I know B-(
But it's all I have to work with to get a scrolling text box.
The idea is to simulate what would be seen on another screen in full size and is only to give an idea of what the end product would look like to the user.

So, they do not need to see the actual content.
I don't understand what you mean by the loop running for its 'own' length. It should run for the length of the content - hence the For i = 1 To Len(Me(txtname))

Have I missed something ?

The thing is , I've tried this in 2000 and it works, but it doesn't work in 97 despite passing the correct text box name to the proc.
If you've run it OK in 97, I guess there must be soemthing screwed up with my textbox somewhere.

cheers,
Graham

Regards,
Graham
 
Actually, I'm running it in '03 ("XP"). But there is noting new / special / unique to the procedure that doesn't exist back to at least '97.





MichaelRed
mlred@verizon.net

 
Well something is weird here. I imported the proc I tried in 2K, set it to run from a button and it ran OK.
I amended it to set a variable for the field name and it still worked.
I changed my procedure to be the same as the one I imported and still it didn't work - it's running on a mouseover.

I then clicked the button,ran the imported proc OK and then when the mouse accidentally moved over the textbox, my new proc then worked !!!
I reloaded the form, ran the mouse over the textbox, error; clicked the button, OK; moved the mouse over the textbox and it worked again!!

I can't see what's going on here, but I've spent too much time on this and as you said Michael, it's flaky.
So I'm going to trash this idea and walk quickly away.

thanks for your help.

Regards,
Graham
 
hmmmmmmmmmmmmmmmmmmmm ... mmmmmmmmmmmmmmmm ... mmm

"flaky ... insn't exactly[/y] what I said ... but perhaps it was implied.

W/o knowing (or necessarily even wanting to know .. ) the overall objective of the app you are trying to demo (' ... proof of concept ... ') it was a bit harsh on my part to note my own bafflement. I suppoer that as they say; theres some good in everything ...

I was, however, really more remarking on the few minor techie issues.

I, however did NOT invoke the scroll procedure via a mouse move event, but resorted to ye olde clicker.




MichaelRed
mlred@verizon.net

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top