473,383 Members | 1,725 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,383 software developers and data experts.

How do I set the Focus to a Popup Dialog?

gnawoncents
214 100+
Greetings,

I have a datasheet, created through VBA, and I am trying to automate setting the column widths to Best Fit. Currently I loop through the controls using the code below

Expand|Select|Wrap|Line Numbers
  1.     'Set width of columns to best fit data
  2.     Dim ctl As Control
  3.     For Each ctl In Forms![Form1].Controls
  4.         If (ctl.ControlType = acTextBox) Then
  5.             ctl.SetFocus
  6.             Call TBBestFit
  7.         End If
  8.     Next ctl 
which calls the function TBBestFit as seen below

Expand|Select|Wrap|Line Numbers
  1. Public Function TBBestFit()
  2.  
  3.   On Error GoTo ErrHandler
  4.  
  5.   SendKeys "%B", False
  6.   DoCmd.RunCommand acCmdColumnWidth
  7.   Exit Function
  8.  
  9. ErrHandler:
  10.  
  11.   Select Case Err
  12.     Case 2046
  13.       'Command not available
  14.       MsgBox "Column width is not available at this time.", vbCritical, "Not Available"
  15.     Case 2501
  16.       'Cancel selected in dialog box - do nothing
  17.     Case Else
  18.       MsgBox Err.Number & ":-" & vbCrLf & Err.Description
  19.   End Select
  20.  
  21. End Function 
This works okay (does anyone know a better way?), but occasionally the popup dialog asking what width the column should be is not active when it first appears. If I click on my selection, then the subsequent iterations flow just fine. So, my question is this: is there any way in VB to set the dialog box as active so the send keys function will work properly?

Thanks in advance for any help.
Feb 4 '11 #1

✓ answered by Lysander

Not sure, but this could be a timing issue. Try putting the command

DoEvents

after your ctl.setfocus and again after your sendkeys.

This allows the computer to catch up and execute the above commands before moving on.

2 4833
Lysander
344 Expert 100+
Not sure, but this could be a timing issue. Try putting the command

DoEvents

after your ctl.setfocus and again after your sendkeys.

This allows the computer to catch up and execute the above commands before moving on.
Feb 5 '11 #2
gnawoncents
214 100+
Thanks Lysander, this seems to have done the trick.
Feb 10 '11 #3

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

Similar topics

1
by: Marko Lahtinen | last post by:
Hello! A part of my website is protected with a .htaccess file. Can I somehow bypass the username/password dialog ?? Can I somehow "hardcode" the authentication name and password in my php-file...
5
by: et | last post by:
Am I correct in that Popup dialog boxes are not available in asp.net? Like the "Are you sure you want to delete?" with yes/no options? What are ways to do this? Thanks for your help. Am new...
0
by: ramendra | last post by:
Hello, I have a asp.net page which has a button and on selection of which i open a small size popup dialog. the dialog has few input parameters and a default button. when i click on the default...
2
by: Kiyomi | last post by:
Hello, I have some codes under event ButtonSend_Click to check the user input values. This check is complicated enough using different stored procedures. Then according the result of the...
3
by: =?Utf-8?B?U3JpZGhhcg==?= | last post by:
Hi, Is there a way to change the title of the Popup opened using window.showModalDialog. I have specified the title in the HTML of the popup. At the end of the title, it is attaching Webpage...
3
by: ApexData | last post by:
I have a Dialog PopUp Form that is called by the following code: DoCmd.OpenForm stDocName, , , stLinkCriteria, cFormReadOnly, acDialog I would like to set the Visible propery of a Label in this...
10
by: ApexData | last post by:
I can't seem to make a PopUp Dialog form Invisible! 'My main form calls the PopUp DoCmd.OpenForm "F-PAUSE", WindowMode:=acDialog 'My PopUp form "F-PAUSE" contains this code Private Sub...
1
by: shawn gong | last post by:
hi all, I have a popup dialog using GTK, which allows user to select "Yes" or "No". Then the program flows depending on the selected answer. The problem is that func() doesn't not wait for...
1
by: Orit | last post by:
I have a question regarding usage of AJAX Control Toolkit's Popup Control Extender . I am using the Popup Control Extender to display a popup dialog ( panel ) from my asp.net page on click of a...
3
by: Mike Hofer | last post by:
Okay, here's the situation: we want to be able to display ASPX pages in an UpdatePanel. The reasons for this are performance related. The site in development uses *lots* of modal popups from some...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.