Solved

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

Posted on 2016-07-21
6
55 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 78

Accepted Solution

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

Expert Comment

by:PatHartman
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 26

Expert Comment

by:Nick67
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks for your help David.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
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…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now