Error 1004

Denny57

Board Regular
Joined
Nov 23, 2015
Messages
246
Office Version
  1. 365
Platform
  1. Windows
I am receiving error 1004 when I try to run the Update Command and select "Yes" from the message box. I have compared the code to similar I use successfully in another file.

So far this error only happens for the "UPDATE" Command following a DATE SEARCH request, however I have provided the entire code as the problem might be caused by another Private Sub
DEBUG shows the error initially occurs at Cells(CurrentRow, 1).Value = DTPicker1.Value and when I exclude this line and "CONTINUE" the error moves on to the next line. This repeats as each line is excluded.

VBA Code:
Dim CurrentRow As Long

Private Sub UserForm_Initialize()

    DTPicker1.Value = ""
    cboSchedulingType.Value = ""
    cboLocation.Value = ""
    txtStartTime.Value = "00:00"
    txtStartTime.MaxLength = 5
    txtFinishTime.Value = "00:00"
    txtFinishTime.MaxLength = 5
    cboPayRate.Value = ""
    CheckBoxPete.Value = False
    CheckBoxKirsty.Value = False
    CheckBoxJan.Value = False
    CheckBoxKelly.Value = False
    CheckBoxCarla.Value = False
    txtWorkDate.Value = ""
    txtDailyPayMonth.Value = ""
    txtDailyWorkHours.Value = ""
    txtDailyLeaveHours.Value = ""
    txtDailyNonWorkingDay.Value = ""
    txtDailyEarningsGross.Value = ""
    txtMonthlyWorkHours.Value = ""
    txtDailyEarningsGross.Value = ""
    txtMonthlyPayMonth.Value = ""
    txtMonthlyWorkHours.Value = ""
    txtMonthlyWorkEarningsGross.Value = ""
    txtMonthlyLeaveHours.Value = ""
    txtMonthlyLeaveEarningsGross.Value = ""
    txtTotalMonthlyEarningsGross.Value = ""
    txtDateSearch.Value = ""
    cboPayMonthSearch.Value = ""
    
    
    DTPicker1.SetFocus
           
End Sub
Private Sub txtStartTime_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    If IsDate(txtStartTime.Value) And Len(txtStartTime.Text) = 5 Then
    Else
        MsgBox "Input Start Time as for example 09:15"
        txtStartTime.Text = ""
    End If

End Sub
Private Sub txtEndTime_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    If IsDate(txtEndTime.Value) And Len(txtEndTime.Text) = 5 Then
    Else
        MsgBox "Input End Time as for example 09:15"
        txtEndTime.Text = ""
    End If

End Sub
Private Sub cmdInputRecords_Click()
Dim lastrow As Long
answer = MsgBox("Add the Record?", vbYesNo + vbQuestion, "Add Record?")
If answer = vbNo Then
Call UserForm_Initialize
DTPicker1.SetFocus
Else
lastrow = Sheets("Daily Hours Input").Range("A" & Rows.Count).End(xlUp).Row
Cells(lastrow + 1, "A").Value = DTPicker1
Cells(lastrow + 1, "B").Value = cboSchedulingType
Cells(lastrow + 1, "C").Value = cboLocation
Cells(lastrow + 1, "E").Value = txtStartTime
Cells(lastrow + 1, "F").Value = txtFinishTime
Cells(lastrow + 1, "K").Value = cboPayRate
Cells(lastrow + 1, "M").Value = CheckBoxPete
Cells(lastrow + 1, "N").Value = CheckBoxKirsty
Cells(lastrow + 1, "O").Value = CheckBoxJan
Cells(lastrow + 1, "P").Value = CheckBoxKelly
Cells(lastrow + 1, "Q").Value = CheckBoxCarla

MsgBox "Record has been added to the database", 0, "Record Added"

With ActiveSheet
    Application.Goto Reference:=.Cells(.Rows.Count, "A").End(xlUp).Offset(-20), Scroll:=True
End With
Call UserForm_Initialize
DTPicker1.SetFocus
End If
End Sub
Private Sub cboPayRate_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim payrate As Double
payrate = cboPayRate.Value
cboPayRate.Value = Format(cboPayRate.Value, "Currency")
End Sub
Private Sub cmdClearForm_Click()
'Clears the User Form
Call UserForm_Initialize
End Sub
Private Sub cmdCloseForm_Click()
'Closes the User Form
    Unload Me
End Sub
Private Sub cmdDateSearch_Click()
'Used to search for records for a specific date

Dim Res As Variant
Dim lastrow
Dim myFind As String
Dim CurrentRow As Long

    Res = Application.Match(CDbl(CDate(txtDateSearch)), Sheets("Daily Hours Input").Range("A:A"), 0)
    If IsError(Res) Then
        MsgBox "Date Not Found", vbInformation, "Date Not Found"
    Call UserForm_Initialize
    txtDateSearch.SetFocus
    Exit Sub
    End If
    
lastrow = Sheets("Daily Hours Input").Range("A" & Rows.Count).End(xlUp).Row
myFind = txtDateSearch
For CurrentRow = 2 To lastrow
If Cells(CurrentRow, 1).Value = myFind Then
DTPicker1.Value = Cells(CurrentRow, 1)
cboSchedulingType.Value = Cells(CurrentRow, 2)
cboLocation.Value = Cells(CurrentRow, 3)
txtStartTime.Value = Cells(CurrentRow, 5)
txtFinishTime.Value = Cells(CurrentRow, 6)
cboPayRate.Value = Cells(CurrentRow, 11)
CheckBoxPete.Value = Cells(CurrentRow, 13)
CheckBoxKirsty.Value = Cells(CurrentRow, 14)
CheckBoxJan.Value = Cells(CurrentRow, 15)
CheckBoxKelly.Value = Cells(CurrentRow, 16)
CheckBoxCarla.Value = Cells(CurrentRow, 17)
txtWorkDate.Value = Cells(CurrentRow, 1).Value
txtDailyPayMonth.Value = Cells(CurrentRow, 4).Value
txtDailyEarningsGross.Value = Cells(CurrentRow, 12).Text
If Cells(CurrentRow, 2).Value = "Work" Then
txtDailyWorkHours.Value = Cells(CurrentRow, 10).Value
ElseIf Cells(CurrentRow, 2).Value = "Leave" Then
txtDailyLeaveHours.Value = Cells(CurrentRow, 10).Value
ElseIf Cells(CurrentRow, 2).Value = "Non-Working Day" Then
txtDailyNonWorkingDay.Value = "Yes"

End If
End If
Next CurrentRow
End Sub
Private Sub cmdUpdateRecords_Click()
'Used to update existing records
Dim CurrentRow As Long
answer = MsgBox("Update the Record?", vbYesNo + vbQuestion, "Update Record?")
If answer = vbNo Then
Call UserForm_Initialize
DTPicker1.SetFocus
Else
Cells(CurrentRow, 1).Value = DTPicker1.Value
Cells(CurrentRow, 2).Value = cboSchedulingType.Value
Cells(CurrentRow, 3).Value = cboLocation.Value
Cells(CurrentRow, 5).Value = txtStartTime.Value
Cells(CurrentRow, 6).Value = txtFinishTime.Value
Cells(CurrentRow, 11).Value = cboPayRate.Value
Cells(CurrentRow, 13).Value = CheckBoxPete.Value
Cells(CurrentRow, 14).Value = CheckBoxKirsty.Value
Cells(CurrentRow, 15).Value = CheckBoxJan.Value
Cells(CurrentRow, 16).Value = CheckBoxKelly.Value
Cells(CurrentRow, 17).Value = CheckBoxCarla.Value

MsgBox "Record has been Updated", 0, "Record Updated"
Call UserForm_Initialize
DTPicker1.SetFocus
End If
End Sub

Any help is most appreciated
 
The additional record is only being added when the last record is being updated. I can probably live with this

Think you may be complicating things a little by repeating codes for both add & updated records where you can do both operations from the same code - you do this by tagging your cmdInputRecords commandbutton with the record status (Add or Update) which, when you press the button, tells the code the action you are taking.

I have not tested but see if this update to your codes helps

MAKE A BACKUP of your workbook & then DELETE ALL existing codes in your userform
  • Place ALL following codes in your userforms code page
Code:
Dim CurrentRow      As Long
Dim wsDailyHours    As Worksheet
Private Sub UserForm_Initialize()

    Set wsDailyHours = ThisWorkbook.Worksheets("Daily Hours Input")
  
    Call cmdClearForm_Click
         
End Sub

Private Sub cmdInputRecords_Click()
    Dim answer      As VbMsgBoxResult
    Dim AddRecord   As Boolean
  
    AddRecord = Val(Me.cmdInputRecords.Tag) = xlAdd
  
    answer = MsgBox(IIf(AddRecord, "Add New", "Update Current") & " Record?", 36, "Information")
    If answer = vbYes Then
      
        'new record
        If AddRecord Then CurrentRow = wsDailyHours.Range("A" & wsDailyHours.Rows.Count).End(xlUp).Row + 1
      
        On Error GoTo myerror
        With wsDailyHours
            .Cells(CurrentRow, 1).Value = DTPicker1.Value
            .Cells(CurrentRow, 2).Value = cboSchedulingType.Value
            .Cells(CurrentRow, 3).Value = cboLocation.Value
            .Cells(CurrentRow, 5).Value = txtStartTime.Value
            .Cells(CurrentRow, 6).Value = txtFinishTime.Value
            .Cells(CurrentRow, 11).Value = cboPayRate.Value
            .Cells(CurrentRow, 13).Value = CheckBoxPete.Value
            .Cells(CurrentRow, 14).Value = CheckBoxKirsty.Value
            .Cells(CurrentRow, 15).Value = CheckBoxJan.Value
            .Cells(CurrentRow, 16).Value = CheckBoxKelly.Value
            .Cells(CurrentRow, 17).Value = CheckBoxCarla.Value
        End With
      
        MsgBox "Record has been " & IIf(AddRecord, "added", "updated") & " to the database", 64, "Information"
      
    End If

    Call cmdClearForm_Click
    DTPicker1.SetFocus
  
myerror:
 If Err <> 0 Then MsgBox (Error(Err)), 48, "Error"
End Sub

Private Sub cmdDateSearch_Click()
    'Used to search for records for a specific date
    Dim rng             As Range
    Dim Res             As Variant, myFind As Variant
  
  
    Set rng = wsDailyHours.Range("A:A")
  
    myFind = Me.txtDateSearch.Value
  
    If Not IsDate(myFind) Then Exit Sub
  
    myFind = CDate(myFind)
  
    Res = Application.Match(CLng(myFind), rng, 0)
  
    If Not IsError(Res) Then
      
        CurrentRow = CLng(Res)
      
        With wsDailyHours
      
            DTPicker1.Value = .Cells(CurrentRow, 1)
            cboSchedulingType.Value = .Cells(CurrentRow, 2)
            cboLocation.Value = .Cells(CurrentRow, 3)
            txtStartTime.Value = .Cells(CurrentRow, 5)
            txtFinishTime.Value = .Cells(CurrentRow, 6)
            cboPayRate.Value = .Cells(CurrentRow, 11)
            CheckBoxPete.Value = .Cells(CurrentRow, 13)
            CheckBoxKirsty.Value = .Cells(CurrentRow, 14)
            CheckBoxJan.Value = .Cells(CurrentRow, 15)
            CheckBoxKelly.Value = .Cells(CurrentRow, 16)
            CheckBoxCarla.Value = .Cells(CurrentRow, 17)
            txtWorkDate.Value = .Cells(CurrentRow, 1).Value
            txtDailyPayMonth.Value = .Cells(CurrentRow, 4).Value
            txtDailyEarningsGross.Value = .Cells(CurrentRow, 12).Text
          
            If .Cells(CurrentRow, 2).Value = "Work" Then
                txtDailyWorkHours.Value = .Cells(CurrentRow, 10).Value
            ElseIf .Cells(CurrentRow, 2).Value = "Leave" Then
                txtDailyLeaveHours.Value = .Cells(CurrentRow, 10).Value
            ElseIf .Cells(CurrentRow, 2).Value = "Non-Working Day" Then
                txtDailyNonWorkingDay.Value = "Yes"
            End If
          
        End With
      
        'update submit commandbutton status
        With Me.cmdInputRecords
            .Tag = xlUpdateState
            .Caption = "Update"
            .BackColor = rgbOrange
        End With
      
    Else
      
        MsgBox "Date Not Found", vbInformation, "Date Not Found"
      
    End If
  
End Sub
Private Sub cboPayRate_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Dim payrate As Double
    payrate = cboPayRate.Value
    cboPayRate.Value = Format(cboPayRate.Value, "Currency")
End Sub
Private Sub cmdClearForm_Click()
'Clears the User Form
    DTPicker1.Value = ""
    cboSchedulingType.Value = ""
    cboLocation.Value = ""
    txtStartTime.Value = "00:00"
    txtStartTime.MaxLength = 5
    txtFinishTime.Value = "00:00"
    txtFinishTime.MaxLength = 5
    cboPayRate.Value = ""
    CheckBoxPete.Value = False
    CheckBoxKirsty.Value = False
    CheckBoxJan.Value = False
    CheckBoxKelly.Value = False
    CheckBoxCarla.Value = False
    txtWorkDate.Value = ""
    txtDailyPayMonth.Value = ""
    txtDailyWorkHours.Value = ""
    txtDailyLeaveHours.Value = ""
    txtDailyNonWorkingDay.Value = ""
    txtDailyEarningsGross.Value = ""
    txtMonthlyWorkHours.Value = ""
    txtDailyEarningsGross.Value = ""
    txtMonthlyPayMonth.Value = ""
    txtMonthlyWorkHours.Value = ""
    txtMonthlyWorkEarningsGross.Value = ""
    txtMonthlyLeaveHours.Value = ""
    txtMonthlyLeaveEarningsGross.Value = ""
    txtTotalMonthlyEarningsGross.Value = ""
    txtDateSearch.Value = ""
    cboPayMonthSearch.Value = ""
  
    DTPicker1.SetFocus
  
    With Me.cmdInputRecords
        .Tag = xlAdd
        .Caption = "Submit"
        .BackColor = vbButtonFace
    End With
End Sub
Private Sub cmdCloseForm_Click()
'Closes the User Form
    Unload Me
End Sub
Private Sub txtStartTime_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    If IsDate(txtStartTime.Value) And Len(txtStartTime.Text) = 5 Then
    Else
        MsgBox "Input Start Time as for example 09:15"
        txtStartTime.Text = ""
    End If
End Sub
Private Sub txtEndTime_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    If IsDate(txtEndTime.Value) And Len(txtEndTime.Text) = 5 Then
    Else
        MsgBox "Input End Time as for example 09:15"
        txtEndTime.Text = ""
    End If
End Sub

Private Sub txtDateSearch_Exit(ByVal Cancel As MSForms.ReturnBoolean)
   Cancel = InValidDate(Me.txtDateSearch)
End Sub

'common function
Function InValidDate(ByVal Box As Object) As Boolean
    Const DateFormat As String = "dd/mm/yyyy"
    With Box
        If Len(.Value) > 0 Then
            If IsDate(.Value) Then
                'format textbox date
                .Value = Format(CDate(.Value), DateFormat)
             Else
                InValidDate = True
            End If
        End If
    End With
    If InValidDate Then MsgBox "Invalid Date Entry", 48, "Invalid Date"
End Function

Note: I have made commandbutton change color when in update mode but you can change this if not required.
Hopefully, update goes in right direction but if not, you can revert back to your original code.

Just as an aside, nothing wrong with your approach but personally, I would also reduce code repetitiveness further by placing the userform data entry controls either in a common code or a worksheet table & read from that but this would involve too much of a re-write.

Dave
 
Last edited:
Upvote 0
Solution

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Think you may be complicating things a little by repeating codes for both add & updated records where you can do both operations from the same code - you do this by tagging your cmdInputRecords commandbutton with the record status (Add or Update) which, when you press the button, tells the code the action you are taking.

I have not tested but see if this update to your codes helps

MAKE A BACKUP of your workbook & then DELETE ALL existing codes in your userform
  • Place ALL following codes in your userforms code page
Code:
Dim CurrentRow      As Long
Dim wsDailyHours    As Worksheet
Private Sub UserForm_Initialize()

    Set wsDailyHours = ThisWorkbook.Worksheets("Daily Hours Input")
 
    Call cmdClearForm_Click
        
End Sub

Private Sub cmdInputRecords_Click()
    Dim answer      As VbMsgBoxResult
    Dim AddRecord   As Boolean
 
    AddRecord = Val(Me.cmdInputRecords.Tag) = xlAdd
 
    answer = MsgBox(IIf(AddRecord, "Add New", "Update Current") & " Record?", 36, "Information")
    If answer = vbYes Then
     
        'new record
        If AddRecord Then CurrentRow = wsDailyHours.Range("A" & wsDailyHours.Rows.Count).End(xlUp).Row + 1
     
        On Error GoTo myerror
        With wsDailyHours
            .Cells(CurrentRow, 1).Value = DTPicker1.Value
            .Cells(CurrentRow, 2).Value = cboSchedulingType.Value
            .Cells(CurrentRow, 3).Value = cboLocation.Value
            .Cells(CurrentRow, 5).Value = txtStartTime.Value
            .Cells(CurrentRow, 6).Value = txtFinishTime.Value
            .Cells(CurrentRow, 11).Value = cboPayRate.Value
            .Cells(CurrentRow, 13).Value = CheckBoxPete.Value
            .Cells(CurrentRow, 14).Value = CheckBoxKirsty.Value
            .Cells(CurrentRow, 15).Value = CheckBoxJan.Value
            .Cells(CurrentRow, 16).Value = CheckBoxKelly.Value
            .Cells(CurrentRow, 17).Value = CheckBoxCarla.Value
        End With
     
        MsgBox "Record has been " & IIf(AddRecord, "added", "updated") & " to the database", 64, "Information"
     
    End If

    Call cmdClearForm_Click
    DTPicker1.SetFocus
 
myerror:
 If Err <> 0 Then MsgBox (Error(Err)), 48, "Error"
End Sub

Private Sub cmdDateSearch_Click()
    'Used to search for records for a specific date
    Dim rng             As Range
    Dim Res             As Variant, myFind As Variant
 
 
    Set rng = wsDailyHours.Range("A:A")
 
    myFind = Me.txtDateSearch.Value
 
    If Not IsDate(myFind) Then Exit Sub
 
    myFind = CDate(myFind)
 
    Res = Application.Match(CLng(myFind), rng, 0)
 
    If Not IsError(Res) Then
     
        CurrentRow = CLng(Res)
     
        With wsDailyHours
     
            DTPicker1.Value = .Cells(CurrentRow, 1)
            cboSchedulingType.Value = .Cells(CurrentRow, 2)
            cboLocation.Value = .Cells(CurrentRow, 3)
            txtStartTime.Value = .Cells(CurrentRow, 5)
            txtFinishTime.Value = .Cells(CurrentRow, 6)
            cboPayRate.Value = .Cells(CurrentRow, 11)
            CheckBoxPete.Value = .Cells(CurrentRow, 13)
            CheckBoxKirsty.Value = .Cells(CurrentRow, 14)
            CheckBoxJan.Value = .Cells(CurrentRow, 15)
            CheckBoxKelly.Value = .Cells(CurrentRow, 16)
            CheckBoxCarla.Value = .Cells(CurrentRow, 17)
            txtWorkDate.Value = .Cells(CurrentRow, 1).Value
            txtDailyPayMonth.Value = .Cells(CurrentRow, 4).Value
            txtDailyEarningsGross.Value = .Cells(CurrentRow, 12).Text
         
            If .Cells(CurrentRow, 2).Value = "Work" Then
                txtDailyWorkHours.Value = .Cells(CurrentRow, 10).Value
            ElseIf .Cells(CurrentRow, 2).Value = "Leave" Then
                txtDailyLeaveHours.Value = .Cells(CurrentRow, 10).Value
            ElseIf .Cells(CurrentRow, 2).Value = "Non-Working Day" Then
                txtDailyNonWorkingDay.Value = "Yes"
            End If
         
        End With
     
        'update submit commandbutton status
        With Me.cmdInputRecords
            .Tag = xlUpdateState
            .Caption = "Update"
            .BackColor = rgbOrange
        End With
     
    Else
     
        MsgBox "Date Not Found", vbInformation, "Date Not Found"
     
    End If
 
End Sub
Private Sub cboPayRate_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Dim payrate As Double
    payrate = cboPayRate.Value
    cboPayRate.Value = Format(cboPayRate.Value, "Currency")
End Sub
Private Sub cmdClearForm_Click()
'Clears the User Form
    DTPicker1.Value = ""
    cboSchedulingType.Value = ""
    cboLocation.Value = ""
    txtStartTime.Value = "00:00"
    txtStartTime.MaxLength = 5
    txtFinishTime.Value = "00:00"
    txtFinishTime.MaxLength = 5
    cboPayRate.Value = ""
    CheckBoxPete.Value = False
    CheckBoxKirsty.Value = False
    CheckBoxJan.Value = False
    CheckBoxKelly.Value = False
    CheckBoxCarla.Value = False
    txtWorkDate.Value = ""
    txtDailyPayMonth.Value = ""
    txtDailyWorkHours.Value = ""
    txtDailyLeaveHours.Value = ""
    txtDailyNonWorkingDay.Value = ""
    txtDailyEarningsGross.Value = ""
    txtMonthlyWorkHours.Value = ""
    txtDailyEarningsGross.Value = ""
    txtMonthlyPayMonth.Value = ""
    txtMonthlyWorkHours.Value = ""
    txtMonthlyWorkEarningsGross.Value = ""
    txtMonthlyLeaveHours.Value = ""
    txtMonthlyLeaveEarningsGross.Value = ""
    txtTotalMonthlyEarningsGross.Value = ""
    txtDateSearch.Value = ""
    cboPayMonthSearch.Value = ""
 
    DTPicker1.SetFocus
 
    With Me.cmdInputRecords
        .Tag = xlAdd
        .Caption = "Submit"
        .BackColor = vbButtonFace
    End With
End Sub
Private Sub cmdCloseForm_Click()
'Closes the User Form
    Unload Me
End Sub
Private Sub txtStartTime_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    If IsDate(txtStartTime.Value) And Len(txtStartTime.Text) = 5 Then
    Else
        MsgBox "Input Start Time as for example 09:15"
        txtStartTime.Text = ""
    End If
End Sub
Private Sub txtEndTime_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    If IsDate(txtEndTime.Value) And Len(txtEndTime.Text) = 5 Then
    Else
        MsgBox "Input End Time as for example 09:15"
        txtEndTime.Text = ""
    End If
End Sub

Private Sub txtDateSearch_Exit(ByVal Cancel As MSForms.ReturnBoolean)
   Cancel = InValidDate(Me.txtDateSearch)
End Sub

'common function
Function InValidDate(ByVal Box As Object) As Boolean
    Const DateFormat As String = "dd/mm/yyyy"
    With Box
        If Len(.Value) > 0 Then
            If IsDate(.Value) Then
                'format textbox date
                .Value = Format(CDate(.Value), DateFormat)
             Else
                InValidDate = True
            End If
        End If
    End With
    If InValidDate Then MsgBox "Invalid Date Entry", 48, "Invalid Date"
End Function

Note: I have made commandbutton change color when in update mode but you can change this if not required.
Hopefully, update goes in right direction but if not, you can revert back to your original code.

Just as an aside, nothing wrong with your approach but personally, I would also reduce code repetitiveness further by placing the userform data entry controls either in a common code or a worksheet table & read from that but this would involve too much of a re-write.

Dave
Dave I realy appreciate all your efforts with this. I will try this a little later and get back to you.
My logical mind and limited VBA knowledge makes me take the careful approach with command buttons for each action. Hopefully once I go through your code I will get an improved understanding of how to architect future projects.

Thanks Again
 
Upvote 0
Dave I realy appreciate all your efforts with this. I will try this a little later and get back to you.
Welcome - nothing complex about updated code - just attempts to follow what most programmers refer to as DRY (do not repeat yourself) coding.

not a criticism of your approach - most projects that have in past been involved with - the code in the userforms tend to look like this

VBA Code:
'----------------------------------------------------------------------------------------------
'                                       COMMANDBUTTONS
'----------------------------------------------------------------------------------------------
Private Sub cmdSubmit_Click()
    RecordAction Me, Val(Me.cmdSubmit.Tag)
End Sub

Private Sub cmdClear_Click()
    RecordAction Me, Val(Me.cmdClear.Tag)
End Sub

Private Sub cmdDelete_Click()
    RecordAction Me, Val(Me.cmdDelete.Tag)
End Sub

Private Sub cmdSearch_Click()
    RecordAction Me, ufFindRecord
End Sub

'-------------------------------------------------------------------------------------------------

Private Sub UserForm_Initialize()
    ConfigureForm Me
End Sub

as you will note, main buttons call a common code passing arguments to it allow each button to perform different actions


Do try it & can always step thru the code to see what it is doing.

Good luck with project

Dave
 
Last edited:
Upvote 0
Dave I realy appreciate all your efforts with this. I will try this a little later and get back to you.
My logical mind and limited VBA knowledge makes me take the careful approach with command buttons for each action. Hopefully once I go through your code I will get an improved understanding of how to architect future projects.

Thanks Again
Dave Thank you again. The Input, Search and Update functions are fineAnd I have changes the cmdInputRecords properties.

I have one last piece of coding to develop which will use another search command button but which could utilize the generic change you have provided.

The requirements are here

Step 1 - Select a value from a Combobox (cboDatePeriod) on the User Form as the search criteria and Click the Command Button
Note - All values for this criteria are stored in Sheet1 Column A
Step 2 - SUM the values of Sheet 1 Column B (Currency format) for those records where the requested criteria are in Column A
Step 3 - Display this SUM value into a TextBox (txtGrossPay) on the User Form

I will also need to repeat the same procedure for the values in Column C (Currency format) and Columns D, E & F (number format - 2 decimal places). The same requested criteria from Column A will be used so the match might only need to be coded once . I am hopeful I can manipulate a solution to accomodate the additional requirements.

I have tried to create code that will match the ComboBox Value to a range which can hopefully be generic fof all 5 SUM functions however this appears to be beyond my abilities.

This is contained in a separate post

 
Upvote 0
with a more involved project it is best to place copy of your workbook (with dummy data) in a file sharing site like dropbox & provide a link to it. This will give those on forum who can assist you a clear understanding of your project & save a lot of time

Dave
 
Upvote 0
with a more involved project it is best to place copy of your workbook (with dummy data) in a file sharing site like dropbox & provide a link to it. This will give those on forum who can assist you a clear understanding of your project & save a lot of time

Dave
Thank you Noted
 
Upvote 0
Thank you Noted
Most Welcome but think you have marked to wrong post as solution. #post 13 is just an unrelated illustration of compact userform coding approach. Think one you should have maked is #Post 11 if indeed, it does what you want.

Dave
 
Upvote 0
Most Welcome but think you have marked to wrong post as solution. #post 13 is just an unrelated illustration of compact userform coding approach. Think one you should have maked is #Post 11 if indeed, it does what you want.

Dave
Dave, once again thank you for your help yesterday. I have resubmitted my other enquiry with a screen shot of a sample worksheet.

Further testing of your code has identified that the "Time" values are being returned as numeric values, something which did not happen previously. I have checked the input code for my original version and the one you kindly created.

Here are examples of the input & Search codes for Start Time (The same happens for Finish Time)

Original Response = 09:00
Revised response = 0.375

Original Input Code
Cells(lastrow + 1, "E").Value = txtStartTime
Revised Input Code
.Cells(CurrentRow, 5).Value = txtStartTime.Value

Original Search Code
txtStartTime.Value = Cells(CurrentRow, 5)
Revised Search Code
txtStartTime.Value =.Cells(CurrentRow, 5)

I am hoping that there is a simple solution to rectify this as I cannot see anything else in the code that has changed that would result in a numeric return

Regards

Dave
 
Upvote 0
Original Search Code
txtStartTime.Value = Cells(CurrentRow, 5)
Revised Search Code
txtStartTime.Value =.Cells(CurrentRow, 5)

I am hoping that there is a simple solution to rectify this as I cannot see anything else in the code that has changed that would result in a numeric return

In the search code, use the Range.Text property to return to your textboxes what you see in the cell & not its underlying value

Rich (BB code):
            txtStartTime.Value = .Cells(CurrentRow, 5).Text
            txtFinishTime.Value = .Cells(CurrentRow, 6).Text

Same would apply to cells containing dates

Dave
 
Upvote 0

Forum statistics

Threads
1,224,809
Messages
6,181,075
Members
453,020
Latest member
mattg2448

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