Auto Command Button

trsisko

Board Regular
Joined
May 20, 2008
Messages
176
I actually want the Command Button the AutoClick in the Code Below. Is this possible?

Code:
Option Explicit
Dim m_Prev_QID() As Integer
Dim m_Next_QID() As Integer
Dim m_QID As Integer
Dim m_ItemNo As Integer
Dim m_Question As String
Dim m_Response As String
Dim m_Validation As String
Dim m_PCSOutput As String
Dim m_TotalUniqueQuestions As Integer
Dim strResponse As String

Private Sub cmbOptions_Change()
    'Get the Option Item Number from the list
    If cmbOptions.ListIndex <> -1 Then
            m_ItemNo = cmbOptions.ListIndex + 1
        m_Response = cmbOptions.Value
     
        cmdNext.Enabled = True
          
    End If
    
End Sub
Private Sub cmdEnd_Click()
    
    Unload Me
    
End Sub
Private Sub cmdNext_Click()

    If txtInput.Visible Then

        Select Case m_Validation
            Case "D": 'Date
           ' UserCalendar.Show
           ' txtInput.Value = UserCalendar.Calendar1.Value
          
                If Not IsDate(m_Response) Then
                   
                    MsgBox "Please enter a valid date !", vbCritical
                    txtInput.SetFocus
                    Exit Sub
                Else
                  
                    m_Response = Format(m_Response, "dd mm yyyy") 'changed in version 7.34. May need to add both date formats
                    
                End If
                
            Case "P" 'Percentage
                If Not IsNumeric(m_Response) Then
                    MsgBox "Please enter a valid % !", vbCritical
                    txtInput.SetFocus
                    Exit Sub
                Else
                    m_Response = Format(m_Response, "0.00%")
                  
                End If
                
            Case "N" 'Numeric - Currency - Term Lenght - Age etc
                If Not IsNumeric(m_Response) Then
                    MsgBox "Please enter a valid Number !", vbCritical
                    txtInput.SetFocus
                    Exit Sub
                Else
                    m_Response = CDbl(m_Response)
                                    End If
                
                        Case "T": 'Free Flow Text
                m_Response = DoSpellCheck(m_Response)
        
            Case Else:
                m_Response = m_Response
                
            
        End Select
        
    End If
        
    strResponse = m_Response
    Call SaveData(m_QID, m_Question, m_Response, m_PCSOutput)
    m_QID = m_Next_QID(m_ItemNo)
    
    Call Question_Load
    txtInput.Value = ""
    cmbOptions.Value = "" 'Fix to Clear Combo Box Prior to New Question Load
    cmdNext.Enabled = (m_Response <> "")
    CmdPrevQuestion.Enabled = True
    
'Opens the Required subforms
    
    'open new catid DC form
    If m_PCSOutput = "32v1.0" Then
    userQuestions.Hide
    ActiveWorkbook.Worksheets("CatOutput").Activate
    Load UserCatIDs
    UserDisplay.Show
    ActiveWorkbook.Worksheets("Output").Activate
    userQuestions.Show
    End If
    
        'open new catid DC form
    If m_PCSOutput = "40v1.0" Then
    userQuestions.Hide
    ActiveWorkbook.Worksheets("invOutput").Activate
    Load UserCatIDs
    UserInvestmentReturns.Show
    ActiveWorkbook.Worksheets("Output").Activate
    userQuestions.Show
    End If
    
    If m_PCSOutput = "End" Then
            userQuestions.Hide
            UserSaveFile.Show
        End If
        
        
        
    'open File Transfer
    If strResponse = "Yes   " Then
    userQuestions.Hide
    Load userTransferImage
    userTransferImage.Show
    ActiveWorkbook.Worksheets("QuestionFront").Activate
    userQuestions.Show
    End If
         
      
    'open Salary Form
    If m_PCSOutput = "S5v1.0 " Then
    userQuestions.Hide
    ActiveWorkbook.Worksheets("SalOutput").Activate
    Load UserSalary
    UserSalary.Show
    ActiveWorkbook.Worksheets("QuestionFront").Activate
    userQuestions.Show
    End If
        
        
        
   'open Address Form
    If m_PCSOutput = "87v1.0" Then
    userQuestions.Hide
    ActiveWorkbook.Worksheets("Address").Activate
    Load UserAddress
    UserAddress.Show
    ActiveWorkbook.Worksheets("QuestionFront").Activate
    userQuestions.Show
    End If
'open Important Notice
  If strResponse = "Yes    " Then
    userQuestions.Hide
    Load userNotice
    userNotice.Show
    ActiveWorkbook.Worksheets("QuestionFront").Activate
    userQuestions.Show
    End If
         

    If m_PCSOutput = "G8A" Then
    lblChar.Visible = True
    End If
    If m_PCSOutput = "1v1.0" Then
    lblChar.Visible = False
    End If

   'Open Signatory
    If m_PCSOutput = "32v1.0" Then
    userQuestions.Hide
    ActiveWorkbook.Worksheets("CatOutput").Activate
    Load UserCatIDs
    UserDisplay.Show
    ActiveWorkbook.Worksheets("Output").Activate
    userQuestions.Show
    End If
    
  
[B]If m_PCSOutput = "4v1.0" Then
UserCalendar.Show
txtInput.Value = UserCalendar.Calendar1.Value[/B]
[B]End If
If m_PCSOutput = "5v1.0" Then
UserCalendar.Show
txtInput.Value = UserCalendar.Calendar1.Value
End If
If m_PCSOutput = "5av1.0" Then
UserCalendar.Show
txtInput.Value = UserCalendar.Calendar1.Value
End If
If m_PCSOutput = "40v1.0" Then
UserCalendar.Show
txtInput.Value = UserCalendar.Calendar1.Value
End If
If m_PCSOutput = "41v1.0" Then
UserCalendar.Show
txtInput.Value = UserCalendar.Calendar1.Value
End If
If m_PCSOutput = "60v1.0" Then
UserCalendar.Show
txtInput.Value = UserCalendar.Calendar1.Value
End If[/B]
[B]End Sub[/B]
Private Sub CmdPrevQuestion_Click()

If m_QID = 1 Then
        m_QID = 1
        CmdPrevQuestion.Enabled = False
    Else
 
        m_QID = QID_Prev(m_Question)
  Call Delete_LastRow
        Call Question_Load
        
        CmdPrevQuestion.Enabled = True
    End If
  
    If m_PCSOutput = "G7" Then
    lblChar.Visible = False
    End If
      If m_PCSOutput = "PC1" Then
    lblChar.Visible = True
    End If
    
End Sub
 
Private Sub txtInput_Change()
lblChar.Caption = Len(Replace(txtInput, "", "")) & " Characters used."
cmdNext.Enabled = (txtInput.Text <> "")
'm_Validation
 m_Response = txtInput.Text
' txtInput.Value = Format(m_Response, "dd mmm yy")
End Sub
Private Sub UserForm_Initialize()
        
    m_QID = 1
    m_TotalUniqueQuestions = TotalQuestions
    Call Question_Load
End Sub
Private Sub Question_Load()
    
    Dim intTotalOptions As Integer
    Dim strQInfo(4) As String
    Dim strOptionsID() As String
    Dim strOptions() As String
    Dim intOptionsControl As Integer
    Dim intOptions As Integer
    
    ReDim m_Next_QID(0)
    ReDim m_Prev_QID(0)
        
    Call Question_Detail(m_QID, strQInfo, intTotalOptions, strOptionsID, strOptions, m_Next_QID, m_Prev_QID, intOptionsControl)
        
    'Update Memory Variables
    m_Question = strQInfo(1)
    m_Validation = strQInfo(3)
    m_PCSOutput = strQInfo(4) 'Get PCS Output Information
    m_Response = QuestionAnswer(m_Question)
    m_ItemNo = 1
    'Load Controls with Data
    Me.Label2.Width = 361.1 * (m_QID / m_TotalUniqueQuestions)
    Me.Label2.Caption = Format((m_QID / m_TotalUniqueQuestions), "0.0%")
    Me.lblQID.Caption = m_QID
    Me.lblQuestion.Caption = m_Question
    Me.LblDesc.Caption = strQInfo(2)
        
    'Hide all Controls
    cmbOptions.Visible = False
    txtInput.Visible = False
    
    'Decide which control should be displayed
    Select Case intOptionsControl
        Case CTRL_OPTION:
        Case CTRL_CHECKBOX:
        Case CTRL_LISTBOX:
        Case CTRL_COMBOBOX: 'Set Combobox
            With cmbOptions
                .Clear
                .Visible = True
                For intOptions = 1 To intTotalOptions
                    .AddItem strOptions(intOptions)
                    If strOptions(intOptions) = m_Response Then .ListIndex = intOptions - 1
                Next intOptions
                
            End With
            
        Case CTRL_TEXTBOX:
            txtInput.Value = m_Response
            txtInput.Visible = True
        
        Case Else:
            txtInput.Visible = True
            
    End Select
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    
    If CloseMode = vbFormControlMenu Then
        MsgBox "Please use the End button to close the form", vbCritical
        Cancel = True
    End If
End Sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Huh?:unsure:

What AutoClick? What command button?
 
Upvote 0
It would be the cmdNext after

Code:
If m_PCSOutput = "4v1.0" Then
UserCalendar.Show
txtInput.Value = UserCalendar.Calendar1.Value
End If
 
Upvote 0

Forum statistics

Threads
1,214,951
Messages
6,122,449
Members
449,083
Latest member
Ava19

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