Avoid transferring any data if all form is not complete?

epardo87

Board Regular
Joined
Feb 24, 2015
Messages
56
Hello, I have the codes below and I want that none of them are transferred if both are not filled. Currently if any of them is empty a window pops up saying "fill everything please" but still transferring data even if they're not all filled (if I fill only the second one and hit Ok button, the data of second one is transferred and the window also pops up):
Appreciate any help!
Code:
'Transfer information


Dim bControlEmpty As Boolean


bControlEmpty = False


    If Len(UserTextBox.Value) > 0 Then
    Cells(emptyRow, 1).Value = UserTextBox.Value
    Else
    bControlEmpty = True
    End If
    If Len(TravelerTextBox.Value) > 0 Then
    Cells(emptyRow, 2).Value = TravelerTextBox.Value
    Else
    bControlEmpty = True
    End If

If bControlEmpty Then
    MissingUserForm.Show
    Unload Me

Else
    Cells(emptyRow, 5).Value = Date
    Unload Me    
End If
 
Try replacing
Code:
    If Len(UserTextBox.Value) > 0 Then
    Cells(emptyRow, 1).Value = UserTextBox.Value
    Else
    bControlEmpty = True
    End If
    If Len(TravelerTextBox.Value) > 0 Then
    Cells(emptyRow, 2).Value = TravelerTextBox.Value
    Else
    bControlEmpty = True
    End If
with
Code:
    If Len(UserTextBox.Value) > 0 And Len(TravelerTextBox.Value) > 0 Then
    Cells(emptyRow, 1).Value = UserTextBox.Value
    Cells(emptyRow, 2).Value = TravelerTextBox.Value
    Else
    bControlEmpty = True
    End If
 
Upvote 0
Thanks a lot! It worked perfectly!
I just have one more question, I also have a Frame with two Option Buttons, I tried to include it likewise (And Len(Frame... ) but It didn't work, how could I include it?
This is the transferring code of the frame:
Code:
    If StartOptionButton.Value = True Then
        Cells(emptyRow, 6).Value = Time
     Else
        Cells(emptyRow, 7).Value = Time
    End If
 
Upvote 0
I stayed a while thinking about it and finally solved it, In case anyone is having the same issue I leave the code below, basically I added another IF below ELSE so that if the first Start Button was not True and Finish Button was also not true, then it means none is selected and it calls my pop up window, best regards!

Code:
    If Len(UserTextBox.Value) > 0 And Len(TravelerTextBox.Value) > 0 And Len(AreaComboBox.Value) > 0 And Len(OperComboBox.Value) > 0 Then
    Cells(emptyRow, 1).Value = UserTextBox.Value
    Cells(emptyRow, 2).Value = TravelerTextBox.Value
    Cells(emptyRow, 3).Value = AreaComboBox.Value
    Cells(emptyRow, 4).Value = OperComboBox.Value
        If StartOptionButton.Value = True Then
            Cells(emptyRow, 6).Value = Time
         Else
            If FinishOptionButton.Value = False Then
                bControlEmpty = True
            Else
                Cells(emptyRow, 7).Value = Time
            End If
        End If
    Else
    bControlEmpty = True
    End If
    
If bControlEmpty Then
    MissingUserForm.Show
Else
    
    Cells(emptyRow, 5).Value = Date


    ThisWorkbook.Save
    
    Unload Me
    
 End If


End Sub
 
Upvote 0
actually later I realized that the form kept transferring data even if option buttons inside the frame were uncheked and the pop up window also appeared, the solution was to place the rest of the values inside each option button alternative:
Code:
Private Sub CancelCommandButton_Click()


Unload Me


End Sub


Private Sub OKCommandButton_Click()


Sheet1.Unprotect Password:="2606"


Dim emptyRow As Long


'Make Sheet1 active
Sheet1.Activate


'Determine emptyRow
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1


'Transfer information


Dim bControlEmpty As Boolean


bControlEmpty = False


        If StartOptionButton.Value = True Then
            If Len(UserTextBox.Value) > 0 And Len(TravelerTextBox.Value) > 0 And Len(AreaComboBox.Value) > 0 And Len(OperComboBox.Value) > 0 Then
                Cells(emptyRow, 1).Value = UserTextBox.Value
                Cells(emptyRow, 2).Value = TravelerTextBox.Value
                Cells(emptyRow, 3).Value = AreaComboBox.Value
                Cells(emptyRow, 4).Value = OperComboBox.Value
                Cells(emptyRow, 6).Value = Time
            Else
                bControlEmpty = True
            End If
        Else
            If FinishOptionButton.Value = False Then
                bControlEmpty = True
            Else
                If Len(UserTextBox.Value) > 0 And Len(TravelerTextBox.Value) > 0 And Len(AreaComboBox.Value) > 0 And Len(OperComboBox.Value) > 0 Then
                    Cells(emptyRow, 1).Value = UserTextBox.Value
                    Cells(emptyRow, 2).Value = TravelerTextBox.Value
                    Cells(emptyRow, 3).Value = AreaComboBox.Value
                    Cells(emptyRow, 4).Value = OperComboBox.Value
                    Cells(emptyRow, 7).Value = Time
                Else
                    bControlEmpty = True
                End If
            End If
        End If
   
If bControlEmpty Then
    MissingUserForm.Show
Else
    
    Cells(emptyRow, 5).Value = Date


    ThisWorkbook.Save
    
    Sheet1.Protect Password:="2606"
    
    Unload Me
    
 End If


End Sub




Private Sub UserForm_Initialize()


'Empty NameTextBox
UserTextBox.Value = ""


'Empty PhoneTextBox
TravelerTextBox.Value = ""


'Fill AreaComboBox
With AreaComboBox
    .AddItem "Elite Chicos"
End With


'Set Elite Chicos as default
AreaComboBox.Value = "Elite Chicos"


'Fill OperComboBox
With OperComboBox
    .AddItem "Hydro"
    .AddItem "Bobinas y Magnetos"
    .AddItem "Aplicación de Feedthru"
    .AddItem "Cableado Inicial"
    .AddItem "Cableado Final"
    .AddItem "Curado"
    .AddItem "Soldadura caja"
End With


'Set StartOptionButton as False
StartOptionButton.Value = False


'Set Focus on UserTextBox
UserTextBox.SetFocus


End Sub
 
Upvote 0

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