Hi ....
Im trying to get my VBA to be a bit clever. What I would like to do is using my reference "sProjectRef" is have a calculation before the data gets added to a table. It currently adds Me.Project.Column(2) and combines it to Me.SubProjectCode.
What I would like to do is IF Me.SubProjectCode column 4 contains "old code" then just use Me.SubprojectCode(2) as sProject and if Me.SubProjectCode is empty then combine "Me.Project.Column(2) & "-" & Me.SubProjectCode" as per the original entry.
Code:
Private Sub AddToSheet_Click()
Dim sActivity As String
Dim sProject As String
Dim sHours As Double
sDescript = Nz(Me.Description, " ")
Me.Description = sDescript
Dim Mysql As String
Dim sLogUser As String
Dim sDate As Date
Dim sCostCode As String
Dim sProjectRef As String
Dim sHourType As String
If Me.Activity = "" Then
MsgBox "You must enter activity before continuing", vbInformation
Me.Activity.SetFocus
Exit Sub
End If
If Me.Project = "" Then
MsgBox "You must enter a Project before continuing", vbInformation
Me.Project.SetFocus
Exit Sub
End If
If Me.LoggedInUser = "" Then
MsgBox "You must enter activity before continuing", vbInformation
Me.LoggedInUser.SetFocus
Exit Sub
End If
sHourType = Me.Hour.Value
sCostCode = Me.CostCode
sActivity = Me.Activity.Column(0)
sProject = Me.Project
sHours = Nz(Me.Hour, 0)
sDescript = Nz(Me.Description, " ")
Me.Description = sDescript
sLogUser = Me.LoggedInUser
sDate = Me.DatePicker
sProjectRef = Me.Project.Column(2) & "-" & Me.SubProjectCode
If sHourType > 0 Then
sHourType = "CD"
Else
sHourType = "CC"
End If
Mysql = "INSERT INTO TimesheetTableTemp (sCostCode, Activity, Project, Hours, HourType, Description, suser, ProjectRef, [task date]) Values "
Mysql = Mysql & "('" & sCostCode & "', '" & sActivity & "', '" & sProject & "', " & sHours & ", '" & sHourType & "', '" & sDescript & "', '" & sLogUser & "', '" & sProjectRef & "', '" + Format(sDate) + "')"
DoCmd.SetWarnings False
DoCmd.RunSQL Mysql
DoCmd.SetWarnings True
Me!TimesheetTableSubform.Form.Requery
ClearField
End Sub
Any ideas please?