Incorrect selection of listbox item on underlying userform.

HighAndWilder

Board Regular
Joined
Nov 4, 2006
Messages
80
Hi All

I have a form 'frmRiders' which has a Command Button to load another form, 'frmSelectClub' from which one can select the club, using a listbox, to which the rider belongs.

The name of the club and the club id are each written to text boxes on the 'frmRiders' form and the 'frmSelectClub' form is hidden prior to it being unloaded when control passes
back to the 'frmRiders' form.

The 'frmSelectClub' sits on top of the 'frmRiders' form and when one selects a club, an item from a listbox directly underneath on the 'frmRiders' form is selected and the event code executed.

Has anybody come across this before and what is the cure / workaround, if any?

Cheers
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
75,362
Office Version
365
Platform
Windows
Are any of the controls on the two forms linked in any way?
 

HighAndWilder

Board Regular
Joined
Nov 4, 2006
Messages
80
Not linked at all but this only happens when the selected item in the listbox on the 'frmSelectClub' is directly over one of the items in the listbox on the 'frmRiders' form. If the items do not appear to overlap then this does not happen.
 

HighAndWilder

Board Regular
Joined
Nov 4, 2006
Messages
80
I have created a stand alone example of this problem.

https://www.dropbox.com/s/27h4bddlngpleqy/DropboxForms.xlsm?dl=0

Please open the form 'frmRiders' and click on the 'Club' button to select a club from the 'frmSelectClub' form.

You will notice that the rider selected on the Riders form changes dependant on where the clubs form is positioned and on which club you select.

I cannot imagine that I am the first person that this has happened to.

Any help appreciated.

Thanks
 

MickG

MrExcel MVP
Joined
Jan 9, 2008
Messages
14,841
Try changing the "Unload Me" to "Hide" as below.

Code:
Private Sub lstClubs_Click()
Dim strMsg As String
If fncIsFormLoaded("frmRiders") Then
     frmRiders!txtClub = Me.lstClubs
   [COLOR="#FF0000"] frmSelectClub.Hide 
[/COLOR]     If Me.chkShowMessage Then
          strMsg = "fvxfcgf"
          MsgBox strMsg, vbInformation, "Information"
     End If
End If
End Sub
 

HighAndWilder

Board Regular
Joined
Nov 4, 2006
Messages
80
Try changing the "Unload Me" to "Hide" as below.

Code:
Private Sub lstClubs_Click()
Dim strMsg As String
If fncIsFormLoaded("frmRiders") Then
     frmRiders!txtClub = Me.lstClubs
   [COLOR="#FF0000"] frmSelectClub.Hide 
[/COLOR]     If Me.chkShowMessage Then
          strMsg = "fvxfcgf"
          MsgBox strMsg, vbInformation, "Information"
     End If
End If
End Sub

That change is not making any difference.

Do you see what the problem is MickG?

Does the change that you have suggested make a difference to how your copy works?

Cheers
 

MickG

MrExcel MVP
Joined
Jan 9, 2008
Messages
14,841
Yes, I See the problem.
I had a problem to find the cause because it did not occur when I stepped through the code, so I recreated the code in a simple format and found the "Unload Me" caused the problem. After removing it and replacing with "frmSelectClub.Hide"
the problem on both codes disappeared.
I've just retested this morning with "Unload Me" and the problem returned !!!

I don't know what else to say, I'm sorry I can't be more helpful !!!
 

HighAndWilder

Board Regular
Joined
Nov 4, 2006
Messages
80
Yes, I See the problem.
I had a problem to find the cause because it did not occur when I stepped through the code, so I recreated the code in a simple format and found the "Unload Me" caused the problem. After removing it and replacing with "frmSelectClub.Hide"
the problem on both codes disappeared.
I've just retested this morning with "Unload Me" and the problem returned !!!

I don't know what else to say, I'm sorry I can't be more helpful !!!

If I put a MsgBox as the last line in the cmdSelectClub_Click event procedure in the frmRiders module the problem is solved.

Another way is to position the frmSelectClub form away from the listbox on the frmRiders form and maybe implement some intelligence so that the user
cannot select a club if there is an overlap.

Neither is ideal but I must move on.

Thanks for taking the time MickG.
 

MickG

MrExcel MVP
Joined
Jan 9, 2008
Messages
14,841
This worked !!!
Open both userforms "VbModeless"

Then set 2nd userform of to left :-
Code:
Private Sub cmdSelectClub_Click()
       Application.ScreenUpdating = True
       frmSelectClub.Show vbModeless
      [COLOR="#FF0000"] frmSelectClub.Left = 50
[/COLOR]       Application.ScreenUpdating = True
End Sub
 

Forum statistics

Threads
1,081,530
Messages
5,359,353
Members
400,524
Latest member
Excelbat

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top