Need Help with Userform Loading

obener

Board Regular
Joined
May 31, 2009
Messages
118
Hi All,

Just a quick question, is there a difference between the play button in vba, userform.show and UserForm_Initialize function? As I am having a bit different reaction from running both ways!

thanks
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
I don't think there's a difference, unless if you are calling a sub which contains UserForm.Show rather than opening the form in the VBE.

What reactions are you having?
 
Upvote 0
I don't think there's a difference, unless if you are calling a sub which contains UserForm.Show rather than opening the form in the VBE.

What reactions are you having?


I got the following in thisworkbook:

Code:
Sub Workbook_Open()

UserForm.Show


End Sub

Then I have a Userform_Initialize() sub to check the tab and generate the listbox but the problem i seem to have is the enter key doesnt always work on the textbox with the Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) function
 
Upvote 0
Does the problem only occur when the form is opened with that code?

What is it you are trying to do with the textbox that involves monitoring for Enter being pressed?
 
Upvote 0
Does the problem only occur when the form is opened with that code?

What is it you are trying to do with the textbox that involves monitoring for Enter being pressed?

Monitoring the enter key checks which subroutine to go to next:

Code:
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)


Select Case KeyCode


  Case 13
   
  If TextLabel.BackColor = RGB(105, 51, 105) Then
  Call SampleMass
  ElseIf TextLabel.BackColor = RGB(51, 51, 105) Then
  Call ContainerNo
  ElseIf TextLabel.BackColor = RGB(51, 255, 255) Then
  Call EquipmentCheck
  ElseIf TextLabel.BackColor = RGB(51, 102, 255) Then
  Call TestNo
  ElseIf TextLabel.BackColor = RGB(255, 102, 255) Then
  Call RemoveContainer
  ElseIf TextLabel.BackColor = RGB(75, 255, 0) Then
  Call WeighContainer
  ElseIf TextLabel.BackColor = RGB(100, 100, 255) Then
  Call ContainerChange
  ElseIf TextLabel.BackColor = RGB(125, 255, 125) Then
  Call CalculationResult
  End If


  Case Else
  End Select
  
  TextboxFocus.Value = ""
  TextboxFocus.Value = "‡"
  
End Sub
 
Upvote 0
The only difference is that i press the green play button or use the userform.show when the workbook is opened as the rest of the code is the same. Thats what is confusing me why it is behaving differently.
 
Upvote 0
What is the user actually entering in the textbox?

By the way, why not use If End If for KeyDown rather thant Select Case, there is only one case after all.
Code:
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)


    If KeyCode = 13 Then

        Select Case Textlabel.BackColor
            Case RGB(105, 51, 105)
                Call SampleMass
            Case RGB(51, 51, 105)
                Call ContainerNo
            Case RGB(51, 255, 255)
                Call EquipmentCheck
            Case RGB(51, 102, 255)
                Call TestNo
            Case RGB(255, 102, 255)
                Call RemoveContainer
            Case RGB(75, 255, 0)
                Call WeighContainer
            Case RGB(100, 100, 255)
                Call ContainerChange
            Case RGB(125, 255, 125)
                Call CalculationResult
        End Select
    End If
    
    TextboxFocus.Value = ""
    TextboxFocus.Value = "‡"

End Sub
 
Upvote 0

Forum statistics

Threads
1,213,534
Messages
6,114,186
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top