Hi,
I'm working on MDI Form.
In first MDI Form set focus set to text box control name txtPayment, and then i create New Form. When i back to old Form (other one MDI Form) how to set focus back to txtPayment?
Thanks
Printable View
Hi,
I'm working on MDI Form.
In first MDI Form set focus set to text box control name txtPayment, and then i create New Form. When i back to old Form (other one MDI Form) how to set focus back to txtPayment?
Thanks
txtPayment.SetFocus
Thanks randem,
I forget to mention, beside txtPayment, other control on previous Form can have the focus to. How to determine what focus have control before this mdi form deactivate?
Screen.ActiveControl I believe
Well i am sure you are talking about MDI Child form.... :confused:
and if you are unloading MDI Child form and going to another form say Form2.. and from Form2 you are again loading MDI Child form.. setting txtPayment TabIndex Property to 0 will help you...
but if you are not unloading MDI Child form.. then write on unload of that Form1... mdichildform.txtpayment.setFocus... or if you are not unloading Form2 just write the same statement on the event where MDI child form is shown again..
Thanks randem, it work (activecontrol)
But i have another question. Since i don't know what type of this control how to determine wheter this control have event/property such as setfocus?
Thank's
Yes moinkhan, it's mdi child form.
Sorry for my lack of explanation fro the problem i facing before.
Follow randem i have this on my form:
VB Code:
Private Sub Form_Activate() If varControlOnFocus Then varControlOnFocus = False If Not varObjectControlOnFocus.Visible Then varObjectControlOnFocus.Visible = True varObjectControlOnFocus.SetFocus End If End Sub Private Sub Form_Deactivate() Set varObjectControlOnFocus = ActiveControl varControlOnFocus = True End Sub
But i dont know how to determine wheter or not this control have setfocus event.
Edited:
How to check if that my variable "varObjectControlOnFocus" to hold variable type of "object" have value or not. Is that "IsEmpty" function will work?
You can easily test for that
VB Code:
On Error Resume Next Err.Clear control.SetFocus If Err.Number <> 0 then ' Control has no SetFocus Event End If On Error GoTo 0
Again, thanks randem. It Solved my problem.
Any other suggestion from you that doesn't using Error trap? to wider my knowledge.
Thanks
If you know what kind of controls have a SetFocus method, you can use this:
VB Code:
Select Case TypeName(varObjectControlOnFocus) Case "TextBox", "PictureBox" 'add other types here varObjectControlOnFocus.SetFocus End Select
without error trapping or specifying which controls:(there might be a way of doing it about looping - but i can't be bothered to sit down and read all the documentation)VB Code:
Private Sub Command1_Click() Debug.Print CanSetFocus(Command1) ' True Debug.Print CanSetFocus(Text1) ' True Debug.Print CanSetFocus(Line1) ' False End Sub ' Requires reference to TypeLib Information Private Function CanSetFocus(ByRef obj As Object) As Boolean Dim objInterfaceInfo As TLI.InterfaceInfo Dim objMemberInfo As TLI.MemberInfo Set objInterfaceInfo = TLI.TLIApplication.InterfaceInfoFromObject(obj) For Each objMemberInfo In objInterfaceInfo.Members If objMemberInfo.Name = "SetFocus" Then Exit For Next objMemberInfo CanSetFocus = Not (objMemberInfo Is Nothing) Set objMemberInfo = Nothing: Set objInterfaceInfo = Nothing End Function
and regarding your other question about checking if an object variable has a value use:VB Code:
If Not [i]object[/i] is Nothing Then '
si_the_geek:
TypeName is what i looking for.
bushmobile:
This method definitely i will use on my application :)
But when i try it it give "User-defined type not defined" on :
VB Code:
objInterfaceInfo As TLI.InterfaceInfo
What should i do?
Thanks guy
:thumb:Quote:
Originally Posted by me
Thanks,
Found it :), used to skip reading comment.