Returning Focus To VB
I have a VB program which instructs an Application (AutoCAD), to do a number of things, including "zoomAll". THis sets the focus on the AutoCAD application. Then to proceed with the VB program's Code, I always have to manually click on the VB interface. This returns the focus to the VB program and so teh VB code is resumed.
The problem this is to be a server program so I need ensure that the focus is returned to the VB program automatically.....Any suggestions would really be appreciated.
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Returning Focus ?
I have a VB6 application that may run for several hours. After a user starts it , he may work in another application, say Excel, then return to mine by clicking it on the task bar. When he does this, the screen does not refresh to me application. Is there a way to show my application's form when the task bar is clicked, even though it is still calculating ?
Thanks for the help.
I have a form with numerous text boxes on it. Not all textboxes have to be completed in order for the user to Add a new record, or Update an existing one. Therefore, I will never know which textbox was the last one filled out before the user hit the Add/Update button.
However, once the Add/Update code has been run, I need to return focus to that last textbox that was filled in, no matter which one it was.
Returning Focus To Word From Vb Macro
I have a vb macro in word that loads a userform the lets you pick from a list to insert text into the document. I am using .insertafter and the userform and insert command botton on the form are working fine. I need the userform to stay on the screen, but I want to return the control to the word document at the cursor.
The problem occurs after the insert. The userform remain in focus. I have to left click on the mouse on the document and hot return to regain focus on the document. SideBar(Hitting ESC after the insert button, repeats the .insertafter command)
Any help on setting focus back to word would be GREATLY appreciated.
Private Sub CmdInsert_Click()
ActiveDocument.Range(Start:=Selection.End, End:=Selection.End).InsertAfter "XXXX"
Returning Control (Focus) To Word From Excel
Hello. I have an "application" that I am creating that involves both Word and Excel. Most of the automation is in Word, including data storage between application sessions.
From Word, a Userform is loaded to collect information. On a button click event, the Word macro launches an Excel instance, loading a specific file. Then, the contents of the Word Userform are placed into cells in the excel document. At this point, the Word document still has the Userform loaded, but Excel has the focus. The user works with the Excel workbook and then hits a custom menu button that calls an Excel macro. The Excel macro then attempts to return control to Word with the dialog box still active.
The problem is this: when the Excel macro runs, it puts excel into a "pending" state, with the hourglass displayed, but it does not re-activate the Word instance. I can manually select the Word instance on the taskbar, and finish the processing I need to complete, but I cannot get Excel to return control/successfully activate the Word instance.
The code I am using to call Word back up from Excel is as follows:
Dim appWord As Word.Application
Dim doc As Word.Document
Set appWord = GetObject(, "Word.Application")
appWord.Visible = True
Set doc = appWord.ActiveDocument
I have tried several variants on the last line, including doc.Activate, doc.ActiveWindow.Activate, etc.
Any ideas are greatly appreciated! :-)
Returning Focus To Form/module Combo
Can I get some suggestions from y'all!
I have a form click event that calls on a module that, given a certain lack of data, the module will direct the user to a new form to select the correct data and then close the new form. My problem is getting the form click event to continue on where it left to break into the separate module and form. I was assuming that since I did not use the 'exit sub' statement, that the focus would return correctly. Everything worked hunky dory until I made the separate module open a new form to obtain data. Any ideas? --Dean
Closing Access From Excel And Returning Focus To Excel...
I'm using a combination of excel and access functions and in the process of automating this.
I have a button in Excel that runs the following:
FILE.mdb contains an auto exec macro that performs the required functions, including closing access (quit) when finished.
However, it only closes if FILE.mdb is opened manually, when FILE.mdb is called by the excel VBA the process problems occur.
How can I get Access to close once finished and then get the next line in the excel VBA to run?
Recordset Only Returning Five Records When It Should Be Returning 466
Doing this in excel with VBA. Haven't working in VBA for a very long time but can't see why I'm getting these results.
I run this sql in query analizer and I get 466 records back but when the same sql runs in vba I only get five records back. I checked the conn string to make sure I was running against the correct db. Is it that I'm not setting up my recordset object correctly?
Set conSql = New ADODB.Connection
conSql.Provider = "SQLOLEDB"
conSql.ConnectionString = "Data Source = Test1;" & "User ID=sa;Password=test; Initial Catalog = test;"
'conSql.ConnectionTimeout = 120
Dim strSql As String
Dim fldField As ADODB.Field
Dim docXML As New MSXML2.DOMDocument
Set rstData = New ADODB.Recordset
strSql = "SELECT CedingCoID, effectivedate, XMLString " & _
"FROM CAPSProgram " & _
"Where ID > 1 and CedingCoID > 1" _
' "WHERE (CedingCoID = '" & intCedingCoID & "' AND EffectiveDate = '" & CDate(datEffectiveDate) & "' AND Description " & IIf(strDescription = vbNullString, "IS NULL)", " = '" & strDescription & "')")
rstData.Open strSql, conSql, adOpenForwardOnly, adLockReadOnly
'Set rstData = conSql.Execute(strSql)
Do Until rstData.EOF
' If Not rstData.EOF Then
globEffectiveDate = rstData.Fields("effectivedate").Value 'set global effective date for future use
docXML.LoadXML (rstData.Fields("XMLString").Value) 'load glabal xmldoc for all load routines
globCedingCoID = rstData.Fields("CedingCoID").Value
How To Give Focus To Activex Component On Form Focus?
Using the Reflections ActiveX component (Reflections is a popular Terminal Editor for connecting with old Alpha/VMS servers), I have a Form with this internal terminal editor ActiveX that obviously needs to have focus to type in.
I've tried setting Form_GotFocus and Form_Click to give focus to the activex component but to no avail. The only thing that works is if I set Form_Repaint to give focus, then it works fine. But repaint causes the window to constantly try to bring itself in front of other Microsoft apps like Word and Outlook and other VB apps when I drag them in front of it. And it keeps flashing in the task bar when I move something non-MS in front of it.
Is there a better way to keep focus on the activex terminal session when the form gets focus without using repaint?
Maintain Line Of Focus After Focus Is Lost On A Listbox ?
I have two listboxes on my firm.
In the first, one selects which Report DLL to use, and then when that is selected, my app creates a new instance of that DLL and loads up all available reports into the second listbox.
So you click on the first listbox, and the blue line select thang goes across that line to show you have selected something.
Just like any other listbox does.
But then you select an item for the second listbox, and the blue line disappears from the first listbox.
So when you're looking at the screen, if you don't remember which DLL you selected, you wouldn't actually know which DLL the second box is referring to.
Ideally the first listbox should retain that blue line while at the same time the second listbox should aswell.
Any thoughts ?
Form Got Focus Or Lost Focus Don't Work
Hi, I have a form that I can't get the Lost Focus or Got Focus events to fire, would anybody know why?
Here is what I am trying to accomplish. I have an .exe vb6 application(MainApp) that opens another .exe vb6(ChildApp) application using the shell command. The main application has a list view with a bunch of records. The ChildApp is used to Insert, Delete or UPdate records from the MainApp. So when an Insert, Update or Delete take place on the Child App, I'd like to refresh the listview on the MainApp because the records have changed. How can I accomplish this? Is there a way to call the form in the Main Application from the Child Application even they are 2 different .exe files? I really need help on this please.
Excel TextBox Font Changes When In Focus And Out Of Focus??
I am using a TextBox within an Excel Sheet and did set the font property to "Terminal" with size 22. When in focus, it seems to be OK but when I click somewhere else in the spreadsheet (TextBox losing focus) the font change. Why is that? I want the font to be the same in-focus or out-of-focus. Any help would be greatly appreciated. I have been playing with this for a while but could not figure it out. By the way, I am using Office 2003.
SendKey To A Window NOT In Focus - But Keep Focus?
Fyi, I'm fairly new to VB.
Anyway, to the point.
I have two applications, both running in full screen.
What I want to accomplish is that while one of the applications are running in focus (full screened), I want my VB program to run in the background and send a key on a regular basis to the other application (the one that is NOT in focus) without having to tab out of the focused application.
I managed to achieve some of this partly with the help of FindWindow and ShowWindow:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Const SW_HIDE = 0
Private Const SW_NORMAL = 1
Private Const SW_MAXIMIZE = 3
Private Const SW_SHOW = 5
Private Const SW_MINIMIZE = 6
Private Const SW_RESTORE = 9
Dim hinst As Long
Dim hinst2 As Long
hinst = FindWindow(vbNullString, "PrgNotInFocus") ' The program that should not be in focus, but have keys sent to
hinst2 = FindWindow(vbNullString, "PrgInFocus") ' Should be in focus at all times
If Not IsNull(hinst) Then
ShowWindow hinst, SW_NORMAL
ShowWindow hinst, SW_MAXIMIZE
This allows me to bring forth the window that I don't want in focus and "makes it press 1".
But that's hardly the effect I'm looking for, since it:
-Tabs out of my current application and focuses the wrong one
-Requires the window I want to SendKeys to to be focused
Get Focus Lose Focus (ASAP)
Hello I have a program that Gets the focus of a text box on intervals and need to "reset" the focus to the application that had the focus before i took it.
For an example:
I am useing internet explorer and the application gets the focus of the text box in my application then i want to "reset" the focus back to internet explorer !
ANY HELP WANTED AND NEEDED
Sorry Vikarmji - Still The Focus Goes There.Focus In Flexgrid - Pls Help Me
My Flexgird contains 32 rows and 5 columns. Focus should not go to specific rows.Iam using the following code
Private Sub Msflexgrid_SelChange()
If .Row = 1 Or .Row = 11 Or .Row = 21 Or .Row = 26 Or .Row = 2 Or .Row = 12 Or .Row = 22 Or .Row = 27 Then
.FocusRect = flexFocusNone
.FocusRect = flexFocusLight
But it is not working properly.
Thanks in Advance
Edited by - dorathy_sylvia on 3/1/2005 8:37:41 PM
Lost Focus /got Focus????
I have an exit button which when pressed displays a msg box. The msgbox asks 'are you sure you want to exit'. The trouble is that if the user selects no i cant find a way to put focus back to the conrol that had focus previously. Does anyone know how to do this and if so give me any pointers?
Focus, Focus, Fovus
What is the code to figure out if a control has focus? I would really like to code:
If SoAndSoControl.HasFocus Then
Do this or that
Is there something similar?
Lost Focus-set Focus
On Lost focus I am checking the len of a text and want the focus to stay on that control
if a check fails , how do i do that
can i just do
Private Sub txtMCCN_LostFocus()
' Validate here if its is less
If (Len(txtMCCN) < 6) Then
MsgBox ("MCCN has to be 6 chars long")
Share what you know and ask what you dont....
I'm using the following command to make a sum from a range of cells.
Dim Pa As Integer
ActiveCell.Offset(1, 5) = WorksheetFunction.Sum(Sheets("BOMA").Range("F5", Sheets("BOMA").Cells(Range("F65536").End(xlUp).Row + 1, 6)))
Pa = ActiveCell.Offset(1, 5)
The program return an error and stops at Pa = ....
Debug shows that Pa = 0 even though the sum in this cell are something else.
Returning From A Sub
Can any one tell me is there a way to return from a sub function
is there a way to return to the place in another function where I called this sub from?
if not is there another way I can run the same procuder and come back to my starting point?
Returning A Value From A Sub?
well I have something along the lines of
public sub returnTest(theNum As integer)if theNum = 1 then'return something elseend ifexit sub
But, I don't know how to return something in vb.
I would like to use this sub like..
testVar = returnTest(1)
Returning A Value From An Exe
I am trying to make an exe which returns a value to the command prompt when run through the command line. I am using cmd line parameters..
Mts, Vb6, W2k, Not Returning
It's only been a week and it's time for me to throw this out to bigger brains then mine.
I have a vb6 app that uses MTS objects to retrieve data and do other nifty db stuff. When it was on nt4 I wrote a report engine that used MTS and generated a html report for the user. Dam* users now want me to implement it on w2k.
I register the dll in component services, run the control on the client that calls it:
Set obj = CreateObject("RDS.DataSpace") Set report = obj.CreateObject("DCISReportEngine.Report", sServer) 'Set report = obj.CreateObject("DCISReportEngine.Report", "localhost") 'should return report url strURL = report.GenerateReport(Conn, sServer, sSQL, sRepDef, boolDup, boolGroup)
Now running locally it runs fine. But when the code above runs it creates the object (starts the package running on the server) but
returns a null string. It should return a string with a url in it.
So I ask what am I not getting? I added a log file to the MTS dll and it doesn't create the log so I'd guess it doesn't run.
But nothing tells me that it doesn't.
Suggestions? Mine regarding giving back my nt4 have gone unanswered.
Thanks for your time,
Returning Value From Exe
Thanks for reading. I want a VB exe which should return a value say some success or failure regarding the operation happening inside it. Just like a C++ program returning a value to the console. And I want my java program to read this. How can I return the value from my VB program?
I Really Don't Know (returning A Value)
My problem is kinda complicated. I have made my own msgbox because the normal msgbox freezes my program and that's not good. But now I can call the function. This opens a form and if it's already openend it put's the info into a type MSGINFO. So far so good. That form raises an event to tell if a button got clicked. Now when that happends I want to return the value to where the sub got called. And that's not possible (I think). But I don't want the sub wich calls the msgbox form to use something like:
LOOP until Clicked
and then save in the boolean clicked if it got clicked cause that uses to much resources and gives up to much time. It's kinda complicated but I hope someone has got an answer.
Why Is It Returning Nothing?!?!?
I have this code piece to try and convert a month in numbers to the actual month like 11/ would be november. But I get a blank msgbox when I try this code and I can not figure out why! thanks for any help!
Dim strdate As String
Dim strmonth As String
Dim theday As String
Dim str2 As String
Dim strday As String
Dim chkmonth As String
strdate = Text1.Text
If Left$(strdate, 3) = "/" Then
Select Case Mid(Text1.Text, 1, 2)
str2 = "October"
str2 = "November"
str2 = "December"
strmonth = str2
API Returning Nothing
I got a few problems...
What do you do when you use a GetText Function to get the text on a window and nothing comes back? Like you know for a fact your code is right and bug free. I thinking the window has something blocking API or something. Some windows and objects dont let you use API on them is that possible? Some windows/objects you can't hide. Like Ad bars that dock on ur computer and stuff. How can you hide em? Also I know of one window i have you can SEE it has a title bar and a caption in it, but an API spy can get it's caption.
- How do you get around all of this? -
- How can I hide the windows i want to hide, and get text from objects that have text in em like a text box or maybe password box, or even a label, and captions? -
Maybe theres something I would use instad of API??
My GetText Function:
Public Function GetText(WindowHandle As Long) As String
Dim TheText As String, TL As Long
TL = SendMessageLong(WindowHandle, WM_GETTEXTLENGTH, 0&, 0&)
TheText = String(TL + 1, " ")
Call SendMessageByString(WindowHandle, WM_GETTEXT, TL + 1, TheText)
TheText = Left(TheText, TL)
GetText$ = TheText
Returning A Value
So I'm working on my gradebook programme. As mentioned in other posts I'm a teacher though not of computers - that's just a hobby.
I have a form with 5 textboxes in an array txtMark(0), txtMark(1) etc.
Each one contains a mark for a quiz. Now, if a student is missing a mark due to absence or something I want to recalculate the average based on the number of marks available. If there are only 4 marks then the divisor for that average should be 4.
Here is my code for the command button to calculate the average
Private Sub cmdAverage_Click()
intDivisor = txtMark().Count 'sets the divisor to the same number as there are textboxes
Dim i As Integer
intTotal = Val(txtMark(0).Text) + Val(txtMark(1).Text) + Val(txtMark(2)) + Val(txtMark(3)) + Val(txtMark(4))
'I know that line is clumsy - I'll tidy it up later
txtAverage = CInt(intTotal / intDivisor)
I also have a function ReCalc which is supposed to iterate through the text boxes and if any of them are empty, the divisor should be reduced accordingly:
Public Function ReCalc(intDivisor) As Integer
Dim i As Integer
Dim ctr As Integer
ctr = 0
Dim ctl As Control
For Each ctl In Controls
If TypeOf ctl Is TextBox Then
If ctl.Text = "" Then
ctr = ctr + 1 ' supposed to count how many text boxes are empty
intDivisor = intDivisor - ctr 'supposed to reduce the divisor by the number of textboxes that are empty
Unfortunately it just doesn't work. intTotal is always divided by 5 regardless of how many textboxes contain text. I'm not getting any errors so it must be a logic error but I can't see it. Any help?
Thanks For Returning...
I juz like to thank the adminstrators of this discussion board...I had so many questions regarding vb programming during the time the board was not functioning and felt so helpless... I took a long time to figure out how to solve problems compared to when I can juz pose the questions to ppl who help out with answering of questions on this board.
Juz to show my gratitude
Returning Mouse Down
Hey, I'm making a game and I have a bunch of Shapes on my form. When a user clicks on one of the shapes I would like it to return which shape it is so I can add a color to the shape that is clicked.
o o o o o <----Shapes (In an array 0-4) called shapePeg
^ ^ ^ ^ ^ <----Colored Shapes named shpRed, shpYellow, shpBlue, shp Green shpOrange
now say the user clicks on the shapePeg(2) shape, I want it to return that shape so that when the user clicks on one of the color shapes, the color will then go into the shapePeg(2)
I hope it isn't to confusing.
Help Returning Line Set?
Hi, i have the following problem.
I have a 6 multine textboxes not linked to eachother in any way, EXCEPT.. that they contain information wich is related to eachother..
like this :
text1: text2: text3: etc
info1 info2 info3
info1 info2 info3
info1 info2 info3
info1 info2 info3
as you can see, the first line of text1 .. contains information relevant to the same line in text2/text3/text4/text5/text6.
if you still dont understand 1 more example :
say we have a chair.. and we put it in a table.
colour type serial
blue antique 123-3472
red old-style 234-4567
now i want those information bits to be linked to eachother by counting the lines on wich they exist.
say i would want to see what would exist on lines 100~200
so therefor i would need it to do this :
1. Count the lines in text1 , start reading from line 100 .. and stop at line 200
2. print those in any way ( im going to write them to a textfile ).
3. then do point 1 for text2 till text6. and print those also.
how would i go by this?
i know how to count the lines and all that
Private Sub Count_Click()
Dim Pieces1() As String
Dim string1 As String
Dim lines As Integer
Dim i As Integer
string1 = Text1.Text
Pieces1 = Split(string1, vbNewLine)
For i = LBound(Pieces1) To UBound(Pieces1)
lines = lines + 1
Count.Text = lines
but then i wouldnt know how to read the content of that single line, and even how to read multiple lines.
Please help me with this!
Jeroen van Vierzen
Old Toolbar Keeps Returning
Has anybody had problems changing to a later version of a custom toolbar.
I have a toolbar that has a menu on it, once an option is clicked it runs a small VBA program. This toolbar was attached the workbook and when opened appeared on the receiving PC.
I added some more options a while ago and I had a lot of problems getting the new toolbar to appear. Again I've added more options and now I'm pulling my hair out because the toolbar is reverting back the original one, version 1.....
I've asked the user to delete the original file and toolbar. There is now nothing on the machine relating to my custom toolbar. I have then deleted the attached toobars from my workbook and saved. Next step is to reattach the latest toolbar to my workbook.
Again the user still gets the old toolbar from 2 versions ago.
VBA: Returning The Top 'x' Results.
I need to display 'x' number of results.
The 'x' is user defined.
The results are generated by a Query then displayed by a report.
I have tried the SQL TOP command, but it appears you cannot link that to an input box located on a Form direct to the Query.
I have tried to generate an incrementing number field in the query, but this was also to no avail. If this would have worked then I could simply limit the amount to display.
Any ideas on this are greatly appreciated.
Returning A Value, Not A Formula
Hey all, I need a little help with something pretty basic. I have a macro that performs a simple calculation. How do I return only the result, the integer information, to the cell without the formula tracking along with it?
ActiveCell.FormulaR1C1 = "=R[-1]C+1"
Thanks for any help on this!
XLS MsgBox Returning A Value
I'm an idiot. I'm sure this is a super easy fix and I'm just overlooking something.
Heres what I have
Private Sub Validate()
Dim EmpName As String
EmpName = Range("B2").Value
Ans = MsgBox("Are you" & " EmpName " & "?", vbYesNo, "Validating")
Select Case Ans
' Code for yes
The Message box shows "Are you EmpName?" It doesn't show like, "Are you DrSwaity?" if thats what was in B2. I think it looks good, but obviously not.
One consideration is B2 contains a "=vlookup" formula. There is a value in the cell...
Anyways, thanks in advance!
Returning A String From A VB6 Std DLL
I have created a standard (not ActiveX) DLL from VB6 and am trying to return a string to the calling application from the DLL function. The problem is that the string returned is in wide character format (nulls in between characters)...is it possible to return it in narrow character format (no inter-character nulls)?
Returning The Address
i whouldnt know what to google to find the answer to this so ill ask on a fourm. i whould like to make a program that can copy itself to another directory. i know how to copy just fine, my problem is that, i dont know how to return the current address of the program. say someone downloads my progam and saves it were ever(c:/downloads/stuff/) for example. how do i make my program return (c:/downloads/stuff/myprogram.exe) as a string, so i can make it copy it and save it to another directory?
Does anyone know how to return a list of filenames from a folder.
In a folder say H:Folder there would be some documents. Documentx, Documenty, Documentz. I would like to populate a list in excel with these filenames.
Hope this makes sense.
Returning The Value From A List Box
Alright, I have a list box and im using my variable.listindex which gets the value of the row that i have selected but i want to take the value that i have in the row. So just tell me.
Returning A Variable
Ok ive made an object, but there is still once piece of code i cant figure out. The object has a few variables (Dim Id As Integer), and has a function to give it the Id. But now If i want to call the ID while the program is running, how do I do it? I have another function called getID() but Im not sure what the command is so i can call that variable and use it. (similar to the return variable command in Java)
Dir Function Returning . And ..
I'm using the dir function to populate an array with the names of folders on a drive. It works fine if you specify the root folder
sFolders = Dir("f:", vbDirectory)
but if i specify a subdirectory, like this
sFolders = Dir("f:sub", vbDirectory)
it lists all the subdirectories off of f:sub but it also lists "." and ".." for the first two elements of my array.
Is there a way to stop this?
Also, is there a difference between dir() and dir$()
Returning Day Of Week
is there a simple function in vb that can return the first day of a given week.
for example week 3 in 2003 gives 13 januari
thnx for the help
blue = -1
green = 0
yellow = 1
red = 2
Public Defcon As type_Defcon
Private Sub Form_Click()
Defcon = Defcon + 1
If Defcon > 2 Then Defcon = -1
This will print the value of Defcon. But how can I print the names? like blue, green etc.
How do i return the listindex from a item in a listbox if i only know the text?
i know how to return the text if you know the listindex
SelItem = List1.List (List1.ListIndex)
But the other way round isn't working...
Returning A Pointer From A DLL
This may be a stupid question (there are no stupid questions, just stupid people asking questions)....
This is my DLL function that returns a pointer to a buffer variable that is passed, as a pointer, the function:
char *PROG_GetHome(char *buff);
and I am trying to build the VB code that calls this function and I am having a little trouble.
Thanks much, DM
Returning Printer Name
I have an application where I need to store a users selection of up to 6 different printers (various default label printers, etc). I am trying to use the Common Dialog to allow the user to select a printer to store, but cannot determine how to find the printer name once returned from the selection using the control.
Thanks in advance.
Returning An Error
In A function or Subrotine, is it possible to return an error to what called it? That way I can use the On Error command more easily.
Returning Values From A VB Exe
I am trying to write an exe file (required by a 3rd party vendor I am integrating my system with) that accepts an arguement (the ID of a particular record in a database) and select the values from the tuple associated with the ID from the database, concatenate the selected fields and return this concatenated string.
Is this at all possible. I mean if i create a standard exe, it is the form_load that runs and since it is a Sub it cannot return a value. I cannot use a dll because the vendor explicity states that an executable (exe) file must be used. It is their system that calls my exe file and I do not have control over how it calls my file. All it does it call my file with an input paramenter and expects the string returned when it calls the exe.
Any help is greatly appreciated. I am a novice to VB and I do apologise if my question sounds silly.
Thanks a million.