UserForm stays in the background

Solved
irongege Posted messages 38993 Registration date   Status Moderator Last intervention   -  
irongege Posted messages 38993 Registration date   Status Moderator Last intervention   -
Bonjour,

I have a problem with a UserForm that does not come to the front when you click a button to display it, while it works with another UserForm.

Here is the code for the first UserForm that displays correctly in the foreground:

Private Sub validnumbatchf2_Click() nbrcarac = Len(TextBoxnumbatchf2.Value) If TextBoxnumbatchf2.Text = "" Or nbrcarac < 9 Or TextBoxdebcyf2.Text = "" Then MsgBox "The batch number or the entered time is incorrect" Else validnumbatchf2.Visible = False matf2.Show ' UserForm that should display End If End Sub


The code for the UserForm that comes to the front correctly:

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) If CloseMode = 0 Then MsgBox "You cannot close this window.", 16 Cancel = CloseMode = 0 End If End Sub Private Sub validmatf2_Click() If Application.CountIf(Range("A92:A109"), TextBox1) >= 1 Then Range("B85").Value = TextBox1.Text Suivi.Labelmatdcyf2.Caption = TextBox1.Text Suivi.Show Suivi.MultiPage1.Value = 2 Suivi.debcyf2.Visible = True ' Button for registration procedure TextBox1.Text = "" matf2.Hide Else: MsgBox "You do not have sufficient rights" End If End Sub


When clicking on the button "Suivi.debcyf2," data is recorded

' -------------------------------recording and printing batch documents F2------------------------------------------------ Private Sub debcyf2_Click() hrdebcyf2.Caption = Format(Date, "dd.mm.yy") Workbooks.Open "C:\Suivi_DLC\Archives_" & Range("C33").Value & "\Batch_BL_N°" & Range("B27").Value & "\Docsuivicharge.xls" [AE114] = Labelnumconfigf2.Caption [AF115] = TextBoxnumbatchf2.Text [AH113] = [Y7] [AE116] = TextBoxdebcyf2.Text [U9] = [AE116] [U11] = Labelnumconfigf2.Caption [S1] = hrdebcyf2.Caption [D42] = Labelmatdcyf2.Caption Call nomprenom [G42] = Labelnomdcyf2.Caption [K42] = Labelprenomdcyf2.Caption If [D33] = "X" Then ' flying pin 1 [AH120] = "X" End If If [E33] = "X" Then ' flying pin 2 [AH121] = "X" End If If [F33] = "X" Then ' flying pin 3 [AH122] = "X" End If If [G33] = "X" Then ' flying pin 4 [AH123] = "X" End If If [H33] = "X" Then ' flying pin 5 [AH124] = "X" End If If [I33] = "X" Then ' flying pin 6 [AH125] = "X" End If If [J33] = "X" Then ' flying pin 7 [AH126] = "X" End If If [K33] = "X" Then ' flying pin 8 [AH127] = "X" End If If [L33] = "X" Then ' flying pin 9 [AH128] = "X" End If If [M33] = "X" Then ' flying pin 10 [AH129] = "X" End If If [N33] = "X" Then ' flying pin 11 [AH130] = "X" End If If [O33] = "X" Then ' flying pin 12 [AH131] = "X" End If [AI120] = [D31] [AI121] = [E31] [AI122] = [F31] [AI123] = [G31] [AI124] = [H31] [AI125] = [I31] [AI126] = [J31] [AI127] = [K31] [AI128] = [L31] [AI129] = [M31] [AI130] = [N31] [AI131] = [O31] 'Application.Run ("Docsuivicharge.xls!macro5impressionsupervisur") 'Application.Run ("Docsuivicharge.xls!Macro6impressioninfobatchregleur") ActiveWorkbook.Save ActiveWindow.Close '------------------------------------poli sheet --------------------------------------------- Workbooks.Open "C:\Suivi_DLC\Archives_" & Range("C33").Value & "\Batch_BL_N°" & Range("B27").Value & "\Poli.xls" [D1] = TextBoxnumbatchf2.Text 'Application.Run ("Poli.xls!impresspoli") ActiveWorkbook.Save ActiveWindow.Close '------------------------------------end poli sheet ----------------------------------------- [A46] = Labelnumbf2.Caption [D64] = [A46] [A48] = Labeltablef2 [D66] = [A48] blencycledansf2.Visible = True numblencyclef2.Visible = True numblencyclef2.Caption = ActiveSheet.Cells(46, 1) tableencyclef2.Visible = True numtableencyclef2.Visible = True numtableencyclef2.Caption = ActiveSheet.Cells(48, 1) debcyf2.Visible = False CommandButton5.Visible = True End Sub


Now my problem arises when clicking on "CommandButton5" – my other UserForm displays in the background.

Private Sub CommandButton5_Click() matfincyf2.Show CommandButton5.Visible = False End Sub


I have tried creating another UserForm and the problem remains the same; this UserForm stays in the background.

If anyone has an idea, it would be nice.
Thank you

Configuration: 929 + 996 = 2

--
"I knew an athlete who claimed to have more spring than his watch. To prove it, he raced against his watch."

1 answer

f894009 Posted messages 17417 Registration date   Status Member Last intervention   1 717
 
Hello,

We need your file without the data from the Excel sheets, just the userforms part

to make it available: click on the following link https://www.cjoint.com/
Don't forget to copy the created link in your next message.

See you!
0
irongege Posted messages 38993 Registration date   Status Moderator Last intervention   5 128
 
I added:
Suivi.Hide in the part of this code:

Private Sub CommandButton5_Click() Suivi.Hide matfincyf2.Show CommandButton5.Visible = False End Sub


and also this to the activation of this userform:
Private Sub UserForm_Activate() With Me .StartUpPosition = 3 .Width = Application.Width .Height = Application.Height .Left = 0 .Top = 0 End With End Sub


and it displays correctly in the foreground.
0