I have usually been able to research what I need to do, especially with a lot of help from this website. Unfortunately I am drawing a blank on how to retrieve the value in an "Edit" control in an application outside of Access. I have been able to do a few versions that even go through every open window and get all the child windows but am only able to return that text in a label.
I located another script that did the same thing but it too doesn't return the values for all "Edit" controls. I have tried various SendMessage functions with no luck. Can anyone please show me the missing piece to make it all work? Here is the code of someones script that shows the same issue I am having. Any help would be greatly appreciated. - Option Explicit
-
-
Private Declare PtrSafe Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
-
(ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
-
Private Declare PtrSafe Function GetClassName Lib "user32" Alias "GetClassNameA" _
-
(ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
-
Private Declare PtrSafe Function GetWindowText Lib "user32" Alias "GetWindowTextA" _
-
(ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
-
Public Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" _
-
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
-
lParam As Any) As Long
-
-
-
Private Const WM_GETTEXT As Long = &HD
-
Private Const WM_GETTEXTLENGTH As Long = &HE&
-
Private X As Integer
-
-
-
'Used a user defined type here rather than Enum so that it works on 97
-
Private Type winEnum
-
winHandle As Integer
-
winClass As Integer
-
winTitle As Integer
-
winHandleClass As Integer
-
winHandleTitle As Integer
-
winHandleClassTitle As Integer
-
End Type
-
Dim winOutputType As winEnum
-
-
Public Sub GetWindows()
-
X = 0
-
winOutputType.winHandle = 0
-
winOutputType.winClass = 1
-
winOutputType.winTitle = 2
-
winOutputType.winHandleClass = 3
-
winOutputType.winHandleTitle = 4
-
winOutputType.winHandleClassTitle = 5
-
-
GetWinInfo 0&, 0, winOutputType.winHandleClassTitle
-
End Sub
-
-
-
Private Sub GetWinInfo(hParent As Long, intOffset As Integer, OutputType As Integer)
-
'Sub to recursively obtain window handles, classes and text
-
'given a parent window to search
-
'Written by Mark Rowlinson
-
'www.markrowlinson.co.uk - The Programming Emporium
-
Dim hwnd As Long, lngRet As Long, y As Integer
-
Dim strText As String
-
Dim L As Long
-
hwnd = FindWindowEx(hParent, 0&, vbNullString, vbNullString)
-
While hwnd <> 0
-
Select Case OutputType
-
Case winOutputType.winClass
-
strText = String$(100, Chr$(0))
-
lngRet = GetClassName(hwnd, strText, 100)
-
Range("a1").Offset(X, intOffset) = Left$(strText, lngRet)
-
Case winOutputType.winHandle
-
Range("a1").Offset(X, intOffset) = hwnd
-
Case winOutputType.winTitle
-
strText = String$(100, Chr$(0))
-
lngRet = GetWindowText(hwnd, strText, 100)
-
If lngRet > 0 Then
-
Range("a1").Offset(X, intOffset) = Left$(strText, lngRet)
-
Else
-
Range("a1").Offset(X, intOffset) = "N/A"
-
End If
-
Case winOutputType.winHandleClass
-
Range("a1").Offset(X, intOffset) = hwnd
-
strText = String$(100, Chr$(0))
-
lngRet = GetClassName(hwnd, strText, 100)
-
Range("a1").Offset(X, intOffset + 1) = "Left$(strText, lngRet)"
-
Case winOutputType.winHandleTitle
-
Range("a1").Offset(X, intOffset) = hwnd
-
strText = String$(100, Chr$(0))
-
lngRet = GetWindowText(hwnd, strText, 100)
-
If lngRet > 0 Then
-
Range("a1").Offset(X, intOffset + 1) = "D " & Left$(strText, lngRet)
-
Else
-
Range("a1").Offset(X, intOffset + 1) = "N/A"
-
End If
-
Case winOutputType.winHandleClassTitle
-
Range("a1").Offset(X, intOffset) = hwnd
-
strText = String$(100, Chr$(0))
-
lngRet = GetClassName(hwnd, strText, 100)
-
-
Range("a1").Offset(X, intOffset + 1) = Left$(strText, lngRet)
-
strText = String$(100, Chr$(0))
-
lngRet = GetWindowText(hwnd, strText, 100)
-
If lngRet > 0 Then
-
Range("a1").Offset(X, intOffset + 2) = Left$(strText, lngRet)
-
'& SendMessage(hwnd, WM_GETTEXT, 100, hParent)
-
Else
-
Range("a1").Offset(X, intOffset + 2) = "N/A"
-
-
-
End If
-
End Select
-
'check for children
-
y = X
-
Select Case OutputType
-
Case Is > 4
-
GetWinInfo hwnd, intOffset + 3, OutputType
-
Case Is > 2
-
GetWinInfo hwnd, intOffset + 2, OutputType
-
Case Else
-
GetWinInfo hwnd, intOffset + 1, OutputType
-
End Select
-
'increment by 1 row if no children found
-
If y = X Then
-
X = X + 1
-
End If
-
'now get next window
-
hwnd = FindWindowEx(hParent, hwnd, vbNullString, vbNullString)
-
Wend
-
-
End Sub
11 2265
Well, I am not off to a good start. I copied the version from Excel not Access but it does the same thing. Sorry about that. I can resubmit if this will cause confusion.
DesktopFlyer,
Welcome to Bytes!
It seems like your code is doing a lot of searching for something when it "seems" that you already know what you are looking for. But, I may not completely understand exactly what you are trying to do.
If you know the application that you are trying to target, then, you should be able to go directly to it: - Call AppActivate(Title:="Document1 - Word", _
-
Wait:=False)
The example above would activate the Word application, but if you had multiple instances of Word open, just the one with Document1 open in it.
Then, there are some ways to navigate another application from within MS Access--none are terribly reliable--but they do work.
I think I would need more information to work anything further on this.
Hope this hepps!
Thank you for the welcome and the feedback, I'm usually too stubborn to ask for help but this one has killed several days now. I am able to have it go to the one application that I need the data from but this way it scrolls through every open window and all of their child windows/controls. I am able to see all the controls but its the "Edit" controls text or value that I cannot retrieve.
Once I get the script to return the text I will then store it in a table.
So far, I've understood that much. Again, if you know which app you are going to, just go to the app. No need to scroll through "everything" to find "one thing" if you already know what it is you are looking for.
Perhaps you can provide more specifics....
Just tell us the application you are looking at and tell us what the "Edit" control is that you are looking for. Speaking in abstracts when trying to provide specific solutions can be time-consuming and not very productive.
I was worried that I wasn't going through all the controls so I went overboard and went through everything. Wasn't trying to be vague, simply didn't think it was a well known program. My bad (again).
The application is Q-Pulse. Attached is a screen shot of one of the windows. I would need to get the text in each of the fields. Also if a radio button or checkbox is used. Fairly simple the name field is simply named txtName, the Account Manager combobox is cbxAcMa. Hope that helps.
So, the only way I know of to work through this is to simulate executing keystrokes in the system (using keybd_event from the user32.dll).
The number one challenge that you will come across is that this method does not (and can not) return the value of a check box. This is because even though a check box returns a value within its own system, the check box as a control has no value, only a "state". So, if you were to simulate navigating to a text box, the "value" that you can add to your clipboard is whatever is in that text box--it is a value that can be copied pasted, changed, etc. The check box simply has a state. Simulating a movement to the check box, there is no data to receive. Simulating a press of the space bar will only change the state of the check box, but not generate any data on its current state.
This also assumes that each of the requisite fields has a specific tab order and that navigation can occur.
I hope this makes sense.
Now, if, based upon some of your previous code (that no one here will be able to test or reproduce--because you have an application that is foreign to probably every other user here), you are able to go directly to the application and identify the names of controls, you may be able to glean the values of those controls. But, that is a guess. I have no idea how to go beyond that. It is very difficult to accurately and reliably automate running in this fashion.
This is quite outside of specific areas of expertise, although I have dabbled in it enough to know this will be a challenge.
Is there a particular reason that you must access the data this way, rather than some form of export? It is a highly irregular means of getting data into a db.
Glad to know its a bit of a challenge and that I wasn't simply overlooking something. The gui almost looks like it was generated out of Filemaker.
Thanks again for your time and assistance. To start off with I'll try getting the text box information. If I am successful there I will go after the really fun items.
As far as doing a simple export, the data changes hourly and the backend is behind a firewall that cannot be accessed. I need to consolidate the data from here with other applications. An export to Excel causes even more complications as the format produced is not user friend to bring into a db.
Non-user friendly data is better than the method you describe. As long as the export is "consistently" non-user friendly, you can work with that. Just link to the spreadsheet and it's unfriendly data, then, as you inport it, manipulate it so that it is more friendly.
It will put a smile on everyone's face!
:-)
I was hoping to then control the app from Access to make my life easier. One can dream.
Trust me.... I am a data guy and an automation guy, but I'll take data over automation every time. Data usually doesn't kick back!
:-P
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Marco Simone |
last post by:
Hi,
I have form with four text box controls.
3 text box controls are bound to table A, and 4 text box control sums values
in this 3 text boxes with formula in Control source.
txtBox4=++
If I...
|
by: Nick Haines |
last post by:
I need to write my own custom text edit control.. but I'm not sure where to
start - I've never written a custom control... the features I want are
somewhat similar to the VS .Net text editor - text...
|
by: Ken |
last post by:
Is there any way I can easily set some text to bold in a
rich text box control. prime example a CHAT GUI, i would
like to set the user name bold. is this possible by
doing so in the message...
|
by: Devhead |
last post by:
i have an delphi application that i'm converting over into c#. one of the
controls on one of my forms is a rich text control. the text is saved as
html to an sql server db. is there a winform text...
|
by: Jim Haynes |
last post by:
I cannot set the tab array for the Rich Text Box
control. After I have text in the control, I try the
following where rtb is the name of the rich text box
control:
rtb.selectall()
Redim...
|
by: Pankaj Jain |
last post by:
Hi
I need a free Rich Text Editor Control for my Desktop application.If source
code is also provided then its cool
Thanks
Pankaj Jain
|
by: Paul_Madden via DotNetMonster.com |
last post by:
I think this question could be answered in one word, either "No" or "Name-of-
the-control".
Am (still unfortunately :-)) having to use .NET 1.1 at work. Would like to
display a simple text file...
|
by: Veksi |
last post by:
Hi, everyone. I have this code when I'm trying to control application. These works correct, but I can’t run the next item of the application. There are buttons Finish and Cancel on the Popup, but how...
|
by: =?Utf-8?B?QmVu?= |
last post by:
Hi,
How can select a single word of text, in any application, e.g. Windows
Explorer, Internet Explorer etc. , without double clicking it and instead use
a combination of mouse and keyboard, for...
|
by: anilkumar025 |
last post by:
Hello,
I have developed an Application in C# which extract text from external application's textbox , I am using user32.dll, The application is working fine but my problem is this -...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |