VBABEGINER
Well-known Member
- Joined
- Jun 15, 2011
- Messages
- 1,284
- Office Version
- 365
- Platform
- 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..
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