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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem sending click to external button

Status
Not open for further replies.

davidck88

Programmer
Jan 5, 2009
27
NL
Hi all . I am trying to send a click to external button. The following code works if i use

'WinCap = "Application session for david"

instead of

WinCap = "Application session for" & Replace(Combo1.Text, "- IT Department", "")

However the value WinCap comes from combobox but needs to modifed before it used . The messagebox shows that replace function changed the data corectly but for some reason when i test it the button on external applicaton doesn't get clicked!! Messagebox shows value of WinCap and it is exact name of the window holding the button!! Could any one tell me why this strange thing happens and how to fix it? since i don't want to manually type the title of window each time.Looking forward for replies.Thanks

Code:
Private Sub Command1_Click()


Dim iHnd As Long
    On Error Resume Next
    iHnd = FindWindow(WindowClass, Combo1.Text)
    
    
Dim WinCap As String
        
        'WinCap = "Application session for david"
        'unfortuenly the next line doesn't work
        WinCap = "Application session for" & Replace(Combo1.Text, "- IT Department", "")
        'MsgBox WinCap
        
          iHnd = getAppSubForm("#32770", WinCap, "Button", 2) 'find  button
        PostMessage iHnd, WM_KEYDOWN, 32, 0 'send space to trigger button press
        PostMessage iHnd, WM_KEYUP, 32, 0 'release space
End Sub

Private Function getAppSubForm(ByVal TargetWinClass As String, _
    ByVal TargetWinCaption As String, ByVal TargetSubClass As String, _
    ByVal TargetSubClassIndex As Integer) As Long
    'set variables in module
    mTargetWinClass = TargetWinClass
    mTargetWinCaption = TargetWinCaption
    mTargetSubClass = TargetSubClass
    mTargetSubClassIndex = TargetSubClassIndex
    'set variables for EnumWindows function
    Dim lRet As Long
    Dim lParam As Long
    'Enum sub windows to get hnd for target
    lRet = EnumWindows(AddressOf FindSubWinds, lParam)
    'return target hnd
    getAppSubForm = mSubFormHnd
End Function
 
opss i fixed it myself .Actually there was a space before -
in "- IT Department", "")so the replace part has to be
" - IT Department", "")!!
 

Instead of:
[tt]MsgBox WinCap[/tt]

Use:
[tt]Debug.Print WinCap[/tt]

And see what you have in Immediate Window. You can see a lot better what you have in WinCap, plus - if you need to - you can copy the text. It works gread, for example, if you want to see your SQL statements that you build in your code.



Have fun.

---- Andy
 
>you can copy the text.

You can copy the text from a MsgBox as well ...
 
Albeit with all the extra gubbins included in the msgbox though... [wink]

HarleyQuinn
---------------------------------
You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before posting.

 

strongm, how do you copy a text from the MsgBox?

I used to use a MsgBox to see my SQLs in code, but found it though to copy text, so I use Debug.Print insted.

Have fun.

---- Andy
 
The standard CTRL-C or CTRL-INS will copy the text from a MsgBox (that has focus). This was an OS feature introduced in XP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top