Preferences Command Button

trsisko

Board Regular
Joined
May 20, 2008
Messages
176
I have the following code which i actually want to be able to switch off and on depending on two different command button clicks. What would be the best way to do this?


Code:
If m_PCSOutput = "4v1.0" Then
UserCalendar.Show
txtInput.Value = Format(UserCalendar.Calendar1.Value, "dd mmm yyyy")
Unload UserCalendar
End If
If m_PCSOutput = "5v1.0" Then
UserCalendar.Show
txtInput.Value = Format(UserCalendar.Calendar1.Value, "dd mmm yyyy")
Unload UserCalendar
End If
If m_PCSOutput = "5av1.0" Then
UserCalendar.Show
txtInput.Value = Format(UserCalendar.Calendar1.Value, "dd mmm yyyy")
Unload UserCalendar
End If
If m_PCSOutput = "40v1.0." Then
UserCalendar.Show
txtInput.Value = Format(UserCalendar.Calendar1.Value, "dd mmm yyyy")
Unload UserCalendar
End If
If m_PCSOutput = "41v1.0." Then
UserCalendar.Show
txtInput.Value = Format(UserCalendar.Calendar1.Value, "dd mmm yyyy")
Unload UserCalendar
End If
If m_PCSOutput = "60v1.0" Then
UserCalendar.Show
txtInput.Value = Format(UserCalendar.Calendar1.Value, "dd mmm yyyy")
Unload UserCalendar
End If
'If m_PCSOutput = "9v1.0" Then
'UserCalendar.Show
'txtInput.Value = Format(UserCalendar.Calendar1.Value, "dd/mm/yyyy")
'Unload UserCalendar
'End If
If m_PCSOutput = "40v1.0" Then
UserCalendar.Show
txtInput.Value = Format(UserCalendar.Calendar1.Value, "dd mmm yyyy")
Unload UserCalendar
End If
If m_PCSOutput = "41v1.0" Then
UserCalendar.Show
txtInput.Value = Format(UserCalendar.Calendar1.Value, "dd mmm yyyy")
Unload UserCalendar
End If
End Sub
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
I'm still a novice with the CASE procedure... but see if this works as a shortened version:

Code:
Sub BLAH()
Select Case m_PCSOutput
    Case "4v1.0", "5v1.0", "5av1.0", "40v1.0.", "60v1.0", "40v1.0", "41v1.0", "9v1.0"
        UserCalendar.Show
        txtInput.Value = Format(UserCalendar.Calendar1.Value, "dd mmm yyyy")
        Unload UserCalendar
End Select
 
Upvote 0
I have produced the following which seems to work as expected. Not sure if i need to declare the public function as a boolean?

Also would it not be possible to base this code on the system DLL version that is in use. i.e

If version 8 of the Calendar.ocx is used I could automatically disable the code?

i.e how would i call the system DLLs andf read the version numbers?


Code:
Private Sub cmdCalendarOff_Click()
Calendar = False
cmdCalendarOn = True
cmdCalendarOff.Enabled = False
cmdCalendarOn.Enabled = True
With Sheets("Scheme")
    .Range("F2").Value = ""
End With
End Sub
Private Sub cmdCalendarOn_Click()
Calendar = True
cmdCalendarOn = False
cmdCalendarOff.Enabled = True
cmdCalendarOn.Enabled = False
With Sheets("Scheme")
    .Range("F2").Value = Calendar
End With
End Sub


Code:
  If Sheets("Scheme").Range("F2").Value = True Then
    Call Calendar
    End If
    
End Sub
Private Function Calendar() As Boolean()
If m_PCSOutput = "4v1.0" Then
UserCalendar.Show
txtInput.Value = Format(UserCalendar.Calendar1.Value, "dd mmm yyyy")
Unload UserCalendar
  Exit Function
End If
If m_PCSOutput = "5v1.0" Then
UserCalendar.Show
txtInput.Value = Format(UserCalendar.Calendar1.Value, "dd mmm yyyy")
Unload UserCalendar
  Exit Function
End If
If m_PCSOutput = "5av1.0" Then
UserCalendar.Show
txtInput.Value = Format(UserCalendar.Calendar1.Value, "dd mmm yyyy")
Unload UserCalendar
  Exit Function
End If
If m_PCSOutput = "40v1.0." Then
UserCalendar.Show
txtInput.Value = Format(UserCalendar.Calendar1.Value, "dd mmm yyyy")
Unload UserCalendar
  Exit Function
End If
If m_PCSOutput = "41v1.0." Then
UserCalendar.Show
txtInput.Value = Format(UserCalendar.Calendar1.Value, "dd mmm yyyy")
Unload UserCalendar
  Exit Function
End If
If m_PCSOutput = "60v1.0" Then
UserCalendar.Show
txtInput.Value = Format(UserCalendar.Calendar1.Value, "dd mmm yyyy")
Unload UserCalendar
  Exit Function
End If
'If m_PCSOutput = "9v1.0" Then
'UserCalendar.Show
'txtInput.Value = Format(UserCalendar.Calendar1.Value, "dd/mm/yyyy")
'Unload UserCalendar
'End If
If m_PCSOutput = "40v1.0" Then
UserCalendar.Show
txtInput.Value = Format(UserCalendar.Calendar1.Value, "dd mmm yyyy")
Unload UserCalendar
  Exit Function
End If
If m_PCSOutput = "41v1.0" Then
UserCalendar.Show
txtInput.Value = Format(UserCalendar.Calendar1.Value, "dd mmm yyyy")
Unload UserCalendar
  Exit Function
End If
End Function
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,895
Members
449,097
Latest member
dbomb1414

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