If...End if combination logic

VBABEGINER

Well-known Member
Joined
Jun 15, 2011
Messages
1,284
Office Version
  1. 365
Platform
  1. Windows
Hi All,
Can anyone help me in below code, to rectify it. Something went wrong in logic.

Situation is, when selecting "Core", submit not happened and when select "Non-Core", submit works.

Also, if on any place we can minimize the code, please do guide / help..
Code:
Private Sub btnsubmit_Click()
Application.ScreenUpdating = False


Dim Cn As New ADODB.Connection
Dim cs As String
Dim rs1 As New ADODB.Recordset
                 
'Case 1
If cmbActivity.Value = "" Or ComboBox1.Value = "" Or TxtCaseID.Value = "" Or TxtEETime.Value = "" Or cmbProjectName = "" Or cmbTaskName.Value = "" Or cmbTaskStatus.Value = "" Then
    MsgBox "Select respective item's"
Else


'case 2
If cmbActivity.Value = "Non-Core" And TxtCaseID.Value = "" And TxtEETime.Value = "" And cmbProjectName = "" And cmbTaskName.Value = "" And cmbTaskStatus.Value = "" Then
If ComboBox1.Value = "" Then
    MsgBox "Select sub non-core activity..!!"
Else
    cs = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\group$\WNA\Timesheet_Data.accdb"
    Cn.Open cs
    rs1.Open "Table1", Cn, adOpenDynamic, adLockOptimistic
    
    With rs1
    .AddNew
    .Fields("Start Date/Time") = Me.txtstartdate
    .Fields("Closed Date/Time") = DateTime.Now
    .Fields("Activity Type") = Me.cmbActivity
    .Fields("Sub Type") = Me.ComboBox1
    .Fields("Comments") = Me.txtcomm
    .Fields("User name") = Me.LblUname
    .Update
    End With
    
    Set rs1 = Nothing
    Cn.Close
    Set Cn = Nothing
    
    txtstartdate.Value = ""
    cmbActivity.Value = ""
    ComboBox1.Value = ""
    cmbTaskStatus.Value = ""
    txtcomm.Value = ""
    
    MsgBox "Details Updated"
    Call UserForm_Initialize


    Exit Sub




'case 3
If cmbActivity.Value = "Core" Then
If ComboBox1.Value = "" Then
    MsgBox "Select sub core activity..!!"
     If TxtCaseID.Value = "" Then
            MsgBox "Copy-Paste CASE ID from EE Tool"
                If TxtEETime.Value = "" Then
                    MsgBox "Copy-Paste EE Time from EE Tool"
                    If cmbProjectName.Value = "" Then
                        MsgBox "Select Project Name.."
                            If cmbTaskName.Value = "" Then
                                MsgBox "Select Task Name.."
                                    If cmbTaskStatus.Value = "" Then
                                        MsgBox "Select Status of the Task"


Else


    cs = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\group$\WNA\Timesheet_Data.accdb"
    Cn.Open cs
    rs1.Open "Table1", Cn, adOpenDynamic, adLockOptimistic
    
    With rs1
    .AddNew
    .Fields("Start Date/Time") = Me.txtstartdate
    .Fields("Closed Date/Time") = DateTime.Now
    .Fields("Activity Type") = Me.cmbActivity
    .Fields("Sub Type") = Me.ComboBox1
    .Fields("Case ID") = Me.TxtCaseID
    .Fields("EE Tool TimeDate") = Me.TxtEETime
    .Fields("Project Name") = Me.cmbProjectName
    .Fields("Task Name") = Me.cmbTaskName
    .Fields("Task Status") = Me.cmbTaskStatus
    .Fields("Comments") = Me.txtcomm
    .Fields("User name") = Me.LblUname
    .Update
    End With
    
    Set rs1 = Nothing
    Cn.Close
    Set Cn = Nothing
    
    txtstartdate.Value = ""
    cmbActivity.Value = ""
    ComboBox1.Value = ""
    TxtCaseID.Value = ""
    TxtEETime.Value = ""
    cmbProjectName.Value = ""
    cmbTaskName.Value = ""
    cmbTaskStatus.Value = ""
    txtcomm.Value = ""
    
    MsgBox "Details Updated"
    Call UserForm_Initialize
        
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If


Application.ScreenUpdating = True
End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
To Other Member too, please share if any one knows solution for this please..
 
Upvote 0

Similar threads

Forum statistics

Threads
1,223,911
Messages
6,175,334
Members
452,636
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