Data from Userform not saving

skoorBmaS

New Member
Joined
Feb 5, 2016
Messages
34
Hi Everyone, I have had a colleague of mine state that a user form which I have created isn't always writing data into the data sheet when they use the user form. I have looked at the VBA and it seems fine to me. Could anyone please take a look and see if there is anything that I am missing?

Code:
Private Sub cmdSave_Click()

Application.ScreenUpdating = False:
Application.Calculation = xlCalculationManual


    'Click Ok
    Dim lRow As Long
    
    'Error Text Box'
If Me.cmbSite = "" Then
 MsgBox "Please enter a Site Name.", vbExclamation, "Staff Hours"
 Me.cmbSite.SetFocus
 End If
 If Me.cmbName = "" Then
 MsgBox "Please enter an Employee Name.", vbExclamation, "Staff Hours"
 Me.cmbName.SetFocus
 End If
If Me.cmbTimeIn = "" Then
 MsgBox "Please enter a Time In Value.", vbExclamation, "Staff Hours"
 Me.cmbTimeIn.SetFocus
 End If
If Me.cmbTimeOut = "" Then
 MsgBox "Please enter a Time Out Value.", vbExclamation, "Staff Hours"
 Me.cmbTimeOut.SetFocus
    End If
    
    Dim ws As Worksheet
    Set ws = Worksheets("Data")
    lRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
    With ws
        .Cells(lRow, 1).Value = DateValue(txtDate.Value)
        .Cells(lRow, 3).Value = Me.cmbSite.Value
        .Cells(lRow, 4).Value = Me.cmbName.Value
        .Cells(lRow, 5).Value = Me.cmbTimeIn.Value
        .Cells(lRow, 6).Value = Me.cmbTimeOut.Value
        .Cells(lRow, 8).Value = Me.cmbTransport.Value
        .Cells(lRow, 9).Value = Me.cmbMethod.Value
        .Cells(lRow, 10).Value = Me.txtTravelTime.Value
        
    End With
    
 'Clear input controls.
    Me.cmbName.Value = ""
    Me.cmbTransport.Value = ""
    Me.cmbMethod.Value = ""
    Me.txtTravelTime.Value = ""


Application.ScreenUpdating = True:
Application.Calculation = xlCalculationAutomatic


    End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Are you sure that someone didn't get into the VBA and change the name of one of the textboxes or any of the coding?

Also, if they don't enter one of the 4 TBs you name at the top, and your If statement returns true to setfocus on that textbox, you don't exit the sub to allow them to try again. As it is, it may set focus to that TB, but it wont stop...it will write whatever data they have.

I suspect they are leaving one or more TBs empty, they click the button, the routine fills whatever they DO have filled out and stops...and they see that as "not entering all data"...which is somewhat true :)
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,323
Members
452,635
Latest member
laura12345

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