473,396 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

VBA Get text from "Edit" Control in Application outside of MA

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.


Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Private Declare PtrSafe Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
  4. (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
  5. Private Declare PtrSafe Function GetClassName Lib "user32" Alias "GetClassNameA" _
  6. (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
  7. Private Declare PtrSafe Function GetWindowText Lib "user32" Alias "GetWindowTextA" _
  8. (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
  9. Public Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" _
  10.  (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
  11.  lParam As Any) As Long
  12.  
  13.  
  14. Private Const WM_GETTEXT              As Long = &HD
  15. Private Const WM_GETTEXTLENGTH As Long = &HE&
  16. Private X As Integer
  17.  
  18.  
  19.  'Used a user defined type here rather than Enum so that it works on 97
  20. Private Type winEnum
  21.     winHandle As Integer
  22.     winClass As Integer
  23.     winTitle As Integer
  24.     winHandleClass As Integer
  25.     winHandleTitle As Integer
  26.     winHandleClassTitle As Integer
  27. End Type
  28. Dim winOutputType As winEnum
  29.  
  30. Public Sub GetWindows()
  31.     X = 0
  32.     winOutputType.winHandle = 0
  33.     winOutputType.winClass = 1
  34.     winOutputType.winTitle = 2
  35.     winOutputType.winHandleClass = 3
  36.     winOutputType.winHandleTitle = 4
  37.     winOutputType.winHandleClassTitle = 5
  38.  
  39.     GetWinInfo 0&, 0, winOutputType.winHandleClassTitle
  40. End Sub
  41.  
  42.  
  43. Private Sub GetWinInfo(hParent As Long, intOffset As Integer, OutputType As Integer)
  44.      'Sub to recursively obtain window handles, classes and text
  45.      'given a parent window to search
  46.      'Written by Mark Rowlinson
  47.      'www.markrowlinson.co.uk - The Programming Emporium
  48.     Dim hwnd As Long, lngRet As Long, y As Integer
  49.     Dim strText As String
  50.     Dim L As Long
  51.     hwnd = FindWindowEx(hParent, 0&, vbNullString, vbNullString)
  52.     While hwnd <> 0
  53.         Select Case OutputType
  54.         Case winOutputType.winClass
  55.             strText = String$(100, Chr$(0))
  56.             lngRet = GetClassName(hwnd, strText, 100)
  57.             Range("a1").Offset(X, intOffset) = Left$(strText, lngRet)
  58.         Case winOutputType.winHandle
  59.             Range("a1").Offset(X, intOffset) = hwnd
  60.         Case winOutputType.winTitle
  61.             strText = String$(100, Chr$(0))
  62.             lngRet = GetWindowText(hwnd, strText, 100)
  63.             If lngRet > 0 Then
  64.                 Range("a1").Offset(X, intOffset) = Left$(strText, lngRet)
  65.             Else
  66.                 Range("a1").Offset(X, intOffset) = "N/A"
  67.             End If
  68.         Case winOutputType.winHandleClass
  69.             Range("a1").Offset(X, intOffset) = hwnd
  70.             strText = String$(100, Chr$(0))
  71.             lngRet = GetClassName(hwnd, strText, 100)
  72.             Range("a1").Offset(X, intOffset + 1) = "Left$(strText, lngRet)"
  73.         Case winOutputType.winHandleTitle
  74.             Range("a1").Offset(X, intOffset) = hwnd
  75.             strText = String$(100, Chr$(0))
  76.             lngRet = GetWindowText(hwnd, strText, 100)
  77.             If lngRet > 0 Then
  78.                 Range("a1").Offset(X, intOffset + 1) = "D " & Left$(strText, lngRet)
  79.             Else
  80.                 Range("a1").Offset(X, intOffset + 1) = "N/A"
  81.             End If
  82.         Case winOutputType.winHandleClassTitle
  83.             Range("a1").Offset(X, intOffset) = hwnd
  84.             strText = String$(100, Chr$(0))
  85.             lngRet = GetClassName(hwnd, strText, 100)
  86.  
  87.             Range("a1").Offset(X, intOffset + 1) = Left$(strText, lngRet)
  88.             strText = String$(100, Chr$(0))
  89.             lngRet = GetWindowText(hwnd, strText, 100)
  90.             If lngRet > 0 Then
  91.                 Range("a1").Offset(X, intOffset + 2) = Left$(strText, lngRet)
  92.                 '& SendMessage(hwnd, WM_GETTEXT, 100, hParent)
  93.             Else
  94.                 Range("a1").Offset(X, intOffset + 2) = "N/A"
  95.  
  96.  
  97.             End If
  98.         End Select
  99.          'check for children
  100.         y = X
  101.         Select Case OutputType
  102.         Case Is > 4
  103.             GetWinInfo hwnd, intOffset + 3, OutputType
  104.         Case Is > 2
  105.             GetWinInfo hwnd, intOffset + 2, OutputType
  106.         Case Else
  107.             GetWinInfo hwnd, intOffset + 1, OutputType
  108.         End Select
  109.          'increment by 1 row if no children found
  110.         If y = X Then
  111.             X = X + 1
  112.         End If
  113.          'now get next window
  114.         hwnd = FindWindowEx(hParent, hwnd, vbNullString, vbNullString)
  115.     Wend
  116.  
  117. End Sub
Nov 6 '18 #1
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.
Nov 6 '18 #2
twinnyfo
3,653 Expert Mod 2GB
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:

Expand|Select|Wrap|Line Numbers
  1. Call AppActivate(Title:="Document1 - Word", _
  2.                  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!
Nov 6 '18 #3
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.
Nov 6 '18 #4
twinnyfo
3,653 Expert Mod 2GB
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.
Nov 6 '18 #5
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.

Attached Images
File Type: jpg QP3.jpg (119.8 KB, 710 views)
Nov 6 '18 #6
twinnyfo
3,653 Expert Mod 2GB
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.
Nov 6 '18 #7
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.
Nov 6 '18 #8
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.
Nov 6 '18 #9
twinnyfo
3,653 Expert Mod 2GB
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!

:-)
Nov 6 '18 #10
I was hoping to then control the app from Access to make my life easier. One can dream.
Nov 6 '18 #11
twinnyfo
3,653 Expert Mod 2GB
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
Nov 6 '18 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

2
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...
3
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...
0
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...
4
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...
2
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...
2
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
0
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...
2
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...
4
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...
0
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 -...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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...
0
jinu1996
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...
0
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...
0
tracyyun
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.