Solved

Access Form and Controls cannot capture user's selection in VBA

Posted on 2016-07-21
6
58 Views
Last Modified: 2016-07-28
I am using a remote session to log in to a PC where I am using Office 2016 to open an Access 2016 database on the server. An autoexec.bat calls up the form. The form has a multiple-column ListBox. I set the listbox dblclick event to grab its selection (multiselected=none), but the code cannot get the selection. I have tried many different ways.

However, if I flip to the code behind and then back to the form again, it then works. I created a copy of the form and, if I first try the original form and it doesn't work, if I then try the copy, I can also capture the the user's choice.

I have no idea what is going on here.
0
Comment
Question by:edison04
6 Comments
 
LVL 79

Accepted Solution

by:
David Johnson, CD, MVP earned 500 total points
ID: 41724030
on the machine  that runs access is the server share location trusted to allow VBA interaction?
0
 
LVL 35

Expert Comment

by:PatHartman
ID: 41724751
Are you saying that you are trying to manipulate a form using OLE automation?  What is an autoexec.bat?  Are you saying that you have an autoexec macro that opens the form?  Where is the code that is attempting to manipulate the form running?  What you are describing sounds like a focus issue.
I set the listbox dblclick event to grab its selection
Please post the code and make sure that the procedure header is included so we can see the event if that is where the code is running.
0
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 41724764
Many versions ago, an AutoExec macro was needed to open a specific form when a database was opened.  For quite a while now, you can do this by specifying the form in the database's Options dialog:

File to use when opening a database
So I recommend dumping the Autoexec macro (I assume that is what it is, not an actual batch file as in older versions of Windows), and selecting the form in the Options dialog.

Then, please post your DblClick code so we can see if there are any problems with it.  For comparison, here is some sample DblClick code for working with a single-select listbox:

Private Sub lstCompanies_DblClick(Cancel As Integer)
'Created by Helen Feddema 22-Jul-2016
'Last modified by Helen Feddema 22-Jul-2016

On Error GoTo ErrorHandler

   Dim strCompanyName As String

   strCompanyName = Me![lstCompanies].Column(1)
   
   Me![txtSelectedCompany].Value = strCompanyName
      
ErrorHandlerExit:
   Exit Sub

ErrorHandler:
   MsgBox "Error No: " & Err.Number _
      & " in " & Me.ActiveControl.Name & " procedure; " _
      & "Description: " & Err.Description
   Resume ErrorHandlerExit
   
End Sub

Open in new window

0
ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

 
LVL 26

Expert Comment

by:Nick67
ID: 41724908
Autoexec.bat
It is the autoexec part that may be causing some consternation.
Waaaaaaaaaaaaaaaay back in the DOS days, autoexec.bat started all your TSR (terminate and stay resident) background processes.  Any DOS and Win9x O/S parsed the autoexec.bat file and ran it.  For giggles, you can name your logon script autoexec.bat, and if your AD or TS profile has that file as its logon script, or if it is in the Start Up folder of the start menu, it gets run.  And if you are old school enough to remember that the file that ran at startup was autoexec.bat, you may very well keep that name.

Access also used that terminology.  To this day, if you have a macro named autoexec, it gets run when Access starts.  I have one.  It calls a VBA function that then does a whole whack of things, including refreshing all the linked tables based on the folder that the database was started from.
The possibilities of what you can do with autoexec in Access are limited only by what you can do in VBA (virtually anything) and not just firing up a starting form.

That all being said, @edison04 has a TS environment that opens an Access database on logon.  I've got that, too.  I don't think any of that is pertinent to the grief at hand, though.

I set the listbox dblclick event to grab its selection (multiselected=none), but the code cannot get the selection. I have tried many different ways.

A double-click in a TS environment might be problematic.  The difference between a double-click and two clicks is all about timing -- and TS may screw that up.

So let's try something for fun.  Put a command button beside the listbox.  Put your capture code in the command box's click event.  Select something in the listbox.  Click the button.  Does THAT work correctly on the first try?  If so, maybe my hunch is right.
0
 

Author Comment

by:edison04
ID: 41725248
Sorry about that Autoexec.bat comment!  very tired. Yeah, it was a macro I named Autoexec.

It was the Security settings. The last version of Access I coded in was mostly 2002 with a little 2007. So I didn't know about the trust settings.

Allowing the network to be trusted took care of the problem. Thanks for all the responses. David thanks for recognizing those symptoms and for your help.
0
 

Author Closing Comment

by:edison04
ID: 41734023
Thanks for your help David.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Local Printing Using Remote Desktop Windows 7 sometimes has issues with printing to a local printer using a Remote Desktop Connection (RDC). The 1st step is to verify that printers are checked on the Local Resources tab of the Remote Desktop C…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question