I have a user form with two separate command buttons to do two different tasks when clicked, that I am trying to combine into just the single command button.
One command button is coded to take the contents of a range of textbox values within the form and enter them when clicked into a dedicated workbook data table.
The user form is a client data sheet and the button is used to enter the details of a new client.
The second button, when clicked will crate a new client folder taking its name from a specific textbox value (client name)
The coding for the first button is quite lengthy as follows:
NOTE: I have stopped TextBox4 from resetting as I have found I need it to remain displayed so when clicking the second button, the code will have the textBox value to give the file its name.
The second button code is a lot simpler:
CommanmdButton10 relates to the first button coding, and the second coding relates to commandButton14.
My goal is to just have the one CommandButton that when clicked it will create the client record and a client folder within the company Admin Folder.
Any help would be greatly appreciated
Thank you
Advent
One command button is coded to take the contents of a range of textbox values within the form and enter them when clicked into a dedicated workbook data table.
The user form is a client data sheet and the button is used to enter the details of a new client.
The second button, when clicked will crate a new client folder taking its name from a specific textbox value (client name)
The coding for the first button is quite lengthy as follows:
VBA Code:
Private Sub Commandbutton10_Click()
Dim rw As Integer
Dim ws As Worksheet
Set ws = Worksheets("Client_Database")
rw = ws.Cells.Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
If Trim(Me.TextBox4.Value) = "" Then
MsgBox "Please enter the Holders Surname field!"
Exit Sub
End If
If Trim(Me.TextBox6.Value) = "" Then
MsgBox "Please enter the Client Account Number field!"
Exit Sub
End If
If Trim(Me.TextBox3.Value) = "" Then
MsgBox "Please enter the card status field!"
Exit Sub
End If
If Trim(Me.TextBox4.Value) = "" Then
MsgBox "Please enter the expiry date field!"
Exit Sub
End If
If Trim(Me.TextBox11.Value) = "" Then
MsgBox "Please enter Company Name field!"
Exit Sub
End If
If Trim(Me.TextBox14.Value) = "" Then
MsgBox "Please enter a Post Code field!"
Exit Sub
End If
If Trim(Me.TextBox21.Value) = "" Then
MsgBox "Please enter Clients Unique Password field!"
Exit Sub
End If
ws.Cells(rw, 1).Value = Me.TextBox6.Value
ws.Cells(rw, 2).Value = Me.TextBox3.Value
ws.Cells(rw, 3).Value = Me.TextBox4.Value
ws.Cells(rw, 4).Value = Me.TextBox11.Value
ws.Cells(rw, 5).Value = Me.TextBox12.Value
ws.Cells(rw, 7).Value = Me.TextBox21.Value
ws.Cells(rw, 8).Value = Me.TextBox14.Value
ws.Cells(rw, 9).Value = Me.TextBox17.Value
ws.Cells(rw, 10).Value = Me.TextBox18.Value
ws.Cells(rw, 13).Value = Me.TextBox20.Value
ws.Cells(rw, 19).Value = Me.TextBox30.Value
Me.TextBox1.SetFocus
TextBox6.Value = ""
TextBox3.Value = ""
TextBox4.Value = ""
TextBox11.Value = ""
TextBox12.Value = ""
TextBox21.Value = ""
TextBox14.Value = ""
TextBox17.Value = ""
TextBox18.Value = ""
TextBox20.Value = ""
TextBox19.Value = ""
If (Me.TextBox6.Value) = "" Then
MsgBox "Your New Client Has Been Added, thank you"
Exit Sub
End If
End Sub
Sub resetForm()
TextBox6.Value = ""
TextBox3.Value = ""
'TextBox4.Value = ""
TextBox11.Value = ""
TextBox12.Value = ""
TextBox21.Value = ""
TextBox14.Value = ""
TextBox17.Value = ""
TextBox18.Value = ""
TextBox20.Value = ""
TextBox19.Value = ""
frmMenu.TextBox6.SetFocus
End Sub
End Sub
NOTE: I have stopped TextBox4 from resetting as I have found I need it to remain displayed so when clicking the second button, the code will have the textBox value to give the file its name.
The second button code is a lot simpler:
VBA Code:
Private Sub CommandButton14_Click()
Dim Newfolder As String, path As String
Newfolder = Trim(TextBox4.Text)
path = "C:\Users\Owner\OneDrive\Desktop\Client Records\CSS_Desktop_System\CSS_Admin\Customer_Records\" & Newfolder
With CreateObject("Scripting.FileSystemObject")
If Not .FolderExists(path) Then .CreateFolder path
MsgBox "Your New Folder has been Created for you"
End With
End Sub
CommanmdButton10 relates to the first button coding, and the second coding relates to commandButton14.
My goal is to just have the one CommandButton that when clicked it will create the client record and a client folder within the company Admin Folder.
Any help would be greatly appreciated
Thank you
Advent