Run a Sub within another Sub

knaabis

Active Member
Joined
Apr 25, 2006
Messages
254
Office Version
  1. 2013
Platform
  1. Windows
I have "Private Sub Command0_Click()"
I need to run inside this Sub other Sub called "Private Sub Command1_Click()"
How to do this?
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Try changing this
Private Sub Command1_Click()

to Public Sub Command1_Click()
 
Upvote 0
And?

For example:

Public Sub Command0_Click()
Bla Bla
End Sub


Public Sub Command1_Click()
Bla Bla Bla
End Sub

I need to run Command1 inside Command0.
How to do this?
 
Upvote 0
In your first routine

Private Sub Command0_Click()
Bla Bla Bla
bla
bla bla
Call Sub Command1_Click
bla
End Sub

I had a similar post yesterday where someone wanted to click a button on another Form from a button on the current form..
Basically saying

in the Command1_Click proc make a call to the Btn_Click proc on another Form

Private Sub Command0_Click()
Call Forms("Form12").btnSQL_Click
End Sub


where btnSQL_Click on Form12 was

NOTE ::: The Private was removed from this Sub
Sub btnSQL_Click()
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim sSQL1 As String
Dim sSQL2 As String
Dim iChecked As Integer

Set db = CurrentDb
On Error Resume Next ' just in case there is alread a query called TempQuery
DoCmd.DeleteObject acQuery, "tempquery"
' create a tempquery
Set qdf = db.CreateQueryDef("tempquery", "select * from Locations")

sSQL1 = "SELECT "
sSQL2 = " FROM LOCATIONS"
iChecked = 0 ' counter of number of check boxes ticked
On Error GoTo Err_btnSQL_Click
' check value of -1 means IT IS CHECKED
If Me.Check0.Value = -1 Then
iChecked = iChecked + 1
sSQL1 = sSQL1 & "EmployeeID " 'field to select/display
End If
If Me.Check2.Value = -1 Then
iChecked = iChecked + 1
If iChecked > 1 Then
sSQL1 = sSQL1 & "," ' if a field already selected, must follow with a comma SQL SYNTAX
End If
sSQL1 = sSQL1 & "EmployeeName "
End If
If Me.Check4.Value = -1 Then
iChecked = iChecked + 1
bla bla....
 
Upvote 0

Forum statistics

Threads
1,203,727
Messages
6,056,981
Members
444,900
Latest member
QuillPet

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