passing forms and controls so I can set focus back to a form from a module 
Author Message
 passing forms and controls so I can set focus back to a form from a module

Nice easy one for you...

The LostFocus event calls sub textSize as shown below. I need to pass the
control and form so that the sub gets them like this frmX.txtX
not as a string, so it can perform this task:

frmX.txtX.setfocus

how do you do that. what do I dimension the parameter as?

this is a generic string length checking routine and has to work on over 100
fields...

thanks in advance

Private Sub TxtTitle_LostFocus()
    textSize Len(TxtTitle), 20, frmTitle, "New Title:"    ', TxtTitle need
to pass the control not its text !
End Sub

Sub textSize(actLength, rightLength As Integer, myForm As Form, name As
String)
                                                                        ',
myControl As Integer stick this in the brackets

'used to validate textboxes do not contain too many characters

If actLength > rightLength Then
    MsgBox ("The text entrered in " & name & " must be no longer than " &
rightLength & " characters")
    Stop
    'in here, I want to set focus to form.control passed in as what?
    'WHAT CAN I PUT HERE.SetFocus
    'Stop
End If

End Sub



Wed, 08 May 2002 03:00:00 GMT  
 passing forms and controls so I can set focus back to a form from a module
Rob,

You could dimension the argument as Control.  Then you could pass any
control to the subprocedure.  You don't need to send the form that the
control is on in order to be able to manipulate the control.  But if you
need to send the form as an argument for some other reason, you could
dimension the argument as Form.  Here is an example of dimensioning the
argument as control:

Public Sub TextSize(myControl As Control)

    myControl.SetFocus

End Sub

Here is an example of calling the sub:

    TextSize Text1

Hope this helps,

Kerry Moorman

Quote:

>Nice easy one for you...

>The LostFocus event calls sub textSize as shown below. I need to pass the
>control and form so that the sub gets them like this frmX.txtX
>not as a string, so it can perform this task:

>frmX.txtX.setfocus

>how do you do that. what do I dimension the parameter as?

>this is a generic string length checking routine and has to work on over
100
>fields...

>thanks in advance

>Private Sub TxtTitle_LostFocus()
>    textSize Len(TxtTitle), 20, frmTitle, "New Title:"    ', TxtTitle need
>to pass the control not its text !
>End Sub

>Sub textSize(actLength, rightLength As Integer, myForm As Form, name As
>String)
>                                                                        ',
>myControl As Integer stick this in the brackets

>'used to validate textboxes do not contain too many characters

>If actLength > rightLength Then
>    MsgBox ("The text entrered in " & name & " must be no longer than " &
>rightLength & " characters")
>    Stop
>    'in here, I want to set focus to form.control passed in as what?
>    'WHAT CAN I PUT HERE.SetFocus
>    'Stop
>End If

>End Sub



Wed, 08 May 2002 03:00:00 GMT  
 passing forms and controls so I can set focus back to a form from a module
thanks for that. I was trying to be too complicated.

you saved me hours!


Quote:
> Rob,

> You could dimension the argument as Control.  Then you could pass any
> control to the subprocedure.  You don't need to send the form that the
> control is on in order to be able to manipulate the control.  But if you
> need to send the form as an argument for some other reason, you could
> dimension the argument as Form.  Here is an example of dimensioning the
> argument as control:

> Public Sub TextSize(myControl As Control)

>     myControl.SetFocus

> End Sub

> Here is an example of calling the sub:

>     TextSize Text1

> Hope this helps,

> Kerry Moorman


> >Nice easy one for you...

> >The LostFocus event calls sub textSize as shown below. I need to pass the
> >control and form so that the sub gets them like this frmX.txtX
> >not as a string, so it can perform this task:

> >frmX.txtX.setfocus

> >how do you do that. what do I dimension the parameter as?

> >this is a generic string length checking routine and has to work on over
> 100
> >fields...

> >thanks in advance

> >Private Sub TxtTitle_LostFocus()
> >    textSize Len(TxtTitle), 20, frmTitle, "New Title:"    ', TxtTitle
need
> >to pass the control not its text !
> >End Sub

> >Sub textSize(actLength, rightLength As Integer, myForm As Form, name As
> >String)

',
> >myControl As Integer stick this in the brackets

> >'used to validate textboxes do not contain too many characters

> >If actLength > rightLength Then
> >    MsgBox ("The text entrered in " & name & " must be no longer than " &
> >rightLength & " characters")
> >    Stop
> >    'in here, I want to set focus to form.control passed in as what?
> >    'WHAT CAN I PUT HERE.SetFocus
> >    'Stop
> >End If

> >End Sub



Wed, 08 May 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. passing forms and controls so I can set focus back to a form from a module

2. Set Focus back on field (Access 2000 form)

3. Pass variable value back to form from module

4. passing focus info form form to form

5. Setting focus back to MDI-form

6. Pass variable form module to a form

7. How do you pass from obj from one form to a module/forms

8. Passing input box value from Form Module to report module

9. Filter by form - how to set focus on a control

10. Problem setting focus to specific control from form load event

11. Backing up forms, modules etc.

12. How to convert old binary module and form files back to text sourc3e

 

 
Powered by phpBB® Forum Software