Issues with User Form submissions

ChrisM92

New Member
Joined
Nov 4, 2020
Messages
21
Office Version
  1. 2019
Platform
  1. Windows
Hello!

I have recently created a User Form for our compliance team to log all compliance items that require payment so we can track what needs deducting from their pay, among other reasons.

I keep having it flagged that people have submitted an item on the form, had the pop up saying it was successfully posted but then when they look at the Data tab, it's not there

As an audit log I recently added in to send an email confirming the item. I can now see that some emails are coming through, that when I then look at the Data tab, aren't there. So for some reason my code thinks it's been successful when it hasn't. The majority work fine, it's just the odd one that fails to go through.

Any ideas?

Full code below, most of it should be irrelevant but didn't want to miss anything out. The first sub is the one posting the data, then there is 2 after that to do with setting up the User Form and filling in the drop boxes



VBA Code:
Private Sub CommandButton1_Click()

'Checks the consultant has Wildcards available to be used
If TypeComboBox.Value = "Wildcard" Then
If WildcardTextBox.Value < 1 Then
MsgBox "No Wildcards Available"
Exit Sub
End If
End If

'Unlock the Data sheet ready for data to be posted
Sheets("Data").Unprotect Password:="1"


NextRow = Worksheets("Data").Cells(Rows.Count, 2).End(xlUp).Row + 1

'Checks for any blanks on the form and rejects the posting if so
With Me
If DateTextBox.Value = "" Then
MsgBox "Date is required"
Exit Sub
ElseIf UNComboBox1.Value = "" Then
MsgBox "Your name required"
Exit Sub
ElseIf LCTextBox.Value = "" Then
MsgBox "Locum Code required"
Exit Sub
ElseIf LNTextBox.Value = "" Then
MsgBox "Locum Name required"
Exit Sub
ElseIf ConsultantComboBox.Value = "" Then
MsgBox "Consultant required"
Exit Sub
ElseIf ItemComboBox.Value = "" Then
MsgBox "Description required"
Exit Sub
ElseIf TypeComboBox.Value = "" Then
MsgBox "Deduction Type required"
Exit Sub


End If
End With

'Copies the data from the form into the data sheet
Worksheets("Input").Range("A" & 2) = UNComboBox1.Value
Worksheets("Data").Range("B" & NextRow) = DateValue(DateTextBox.Value)
Worksheets("Data").Range("C" & NextRow) = LNTextBox.Value
Worksheets("Data").Range("D" & NextRow) = LCTextBox.Value
Worksheets("Data").Range("E" & NextRow) = UNComboBox1.Value
Worksheets("Data").Range("F" & NextRow) = ConsultantComboBox.Value
Worksheets("Data").Range("G" & NextRow) = ItemComboBox.Value
Worksheets("Data").Range("I" & NextRow) = AmountTextBox.Value
Worksheets("Data").Range("H" & NextRow) = TypeComboBox.Value
Worksheets("Data").Range("J" & NextRow) = EclipseCheckBox.Value
If TypeComboBox.Value = "Wildcard" Then
Worksheets("Data").Range("L" & NextRow) = DateValue(DateTextBox.Value)
Else
Worksheets("Data").Range("L" & NextRow) = "No"
End If

'save the workbook and then email the compliance officer and myself to confirm its done
ActiveWorkbook.Save


    Dim OutApp As Object, OutMail As Object
    
    Set OutApp = CreateObject("Outlook.Application")
     Set OutMail = OutApp.CreateItem(0)


            With OutMail
                .To = Worksheets("Input").Range("B2").Value
                .CC = Worksheets("Input").Range("A1").Value
                .Subject = LCTextBox.Value & TypeComboBox.Value & ItemComboBox.Value
                .HTMLBody = ""
                .Send
                
            End With


MsgBox "Successfully Submitted"

'Resets the form
DateTextBox.Value = Format(Date, "dd/mm/yyyy")
DateTextBox.Locked = True
LNTextBox.Value = ""
LCTextBox.Value = ""
UNComboBox1.Value = ""
ConsultantComboBox.Value = ""
ItemComboBox.Value = ""
AmountTextBox.Value = ""
TypeComboBox.Value = ""
EclipseCheckBox.Value = ""


With Worksheets("Data").UsedRange.Columns("B").Cells
    .TextToColumns Destination:=.Cells(1), DataType:=xlFixedWidth, FieldInfo:=Array(0, xlYMDFormat)
    .NumberFormat = "dd/mm/yyyy"
End With

'Lock the Data sheet again as only Managers can amend the Data tab
Sheets("Data").Protect Password:="1"
Sheets("Data").Protect AllowFiltering:=True


End Sub




Private Sub ConsultantComboBox_Change()


Dim AvailableWildcards As String


On Error Resume Next
AvailableWildcards = WorksheetFunction.VLookup(ConsultantComboBox.Value, Worksheets("Wildcards").Range("A1:E47"), 5, False)
On Error GoTo 0


WildcardTextBox.Value = AvailableWildcards
WildcardTextBox.Locked = True


End Sub


Private Sub UserForm_Initialize()
Dim xRg As Range
    DateTextBox.Value = Format(Date, "dd/mm/yyyy")
    DateTextBox.Locked = True
  Set xRg = Worksheets("Source").Range("B1:C13")
    Me.ItemComboBox.List = xRg.Columns(1).Value
    Set x2Rg = Worksheets("Source").Range("G1:G47")
    Me.ConsultantComboBox.List = x2Rg.Columns(1).Value
       Set x3Rg = Worksheets("Source").Range("K1:K7")
    Me.TypeComboBox.List = x3Rg.Columns(1).Value
    AmountTextBox.Locked = True
    Set UNxRg = Worksheets("Source").Range("E1:E26")
  Me.UNComboBox1.List = UNxRg.Columns(1).Value


End Sub


Private Sub ItemComboBox_Change()
    
    On Error Resume Next
    ItemCost = WorksheetFunction.VLookup(ItemComboBox.Value, Worksheets("Source").Range("B:C"), 2, False)
On Error GoTo 0


AmountTextBox.Value = ItemCost
AmountTextBox.Locked = True
        
    End Sub


Private Sub LCTextBox_AfterUpdate()


If Len(Me.LCTextBox.Value) <> 9 Then
 MsgBox "Please Check your Candidate Code - Incorrect Format"
 Me.LCTextBox.Value = Left(Me.LCTextBox.Value, 50)
End If


On Error Resume Next
LocumName = WorksheetFunction.VLookup(LCTextBox.Value, Worksheets("TSP").Range("G:J"), 4, False)
On Error GoTo 0


On Error Resume Next
LNTextBox = LocumName
On Error GoTo 0


If LNTextBox <> "" Then
LNTextBox.Locked = True
Else: LNTextBox.Locked = False
End If


End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Can't see anything wrong with the code, why not add the value of "NextRow" to the email, that way you know what row the data should be on & whether it's being overwritten by another entry.
 
Upvote 0
Good shout, thanks

The only thing I could think of, if the Data tab has been filtered would that cause issues? I tried adding a line in to remove any filters but it kept causing the errors
 
Upvote 0
Yes if the sheet is filtered you will get the last visible row, rather then last row of data
 
Upvote 0
Solution
It sounds like you have a userform that takes data and writes to a worksheet. I'm thinking that procedurally, the notification and the "is everything done" routines should b separate from the data entry routine. They should not look to the user entry for data, but only to the worksheet.
 
Upvote 0
Hi,
try updating the section of code that writes to the worksheet with following & see if makes any difference

VBA Code:
With ThisWorkbook.Worksheets("Data")
NextRow = .Cells(.Rows.Count, 2).End(xlUp).Row + 1
    .Range("B" & NextRow) = DateValue(DateTextBox.Value)
    .Range("C" & NextRow) = LNTextBox.Value
    .Range("D" & NextRow) = LCTextBox.Value
    .Range("E" & NextRow) = UNComboBox1.Value
    .Range("F" & NextRow) = ConsultantComboBox.Value
    .Range("G" & NextRow) = ItemComboBox.Value
    .Range("I" & NextRow) = AmountTextBox.Value
    .Range("H" & NextRow) = TypeComboBox.Value
    .Range("J" & NextRow) = EclipseCheckBox.Value
    .
   If TypeComboBox.Value = "Wildcard" Then
        .Range("L" & NextRow) = DateValue(DateTextBox.Value)
    Else
        .Range("L" & NextRow) = "No"
    End If
End With

Dave
 
Upvote 0
It sounds like you have a userform that takes data and writes to a worksheet. I'm thinking that procedurally, the notification and the "is everything done" routines should b separate from the data entry routine. They should not look to the user entry for data, but only to the worksheet.

So change it to be a check to say if NextRow A, B ect is blank then posting failed, otherwise all good?
 
Upvote 0
What did you add & what errors did you get?
I had another go this morning and seems to be working this time around.

Hopefully this and moving the way the confirmation message works will stop anymore getting through

Thanks!
 
Upvote 0
Glad it's sorted & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

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