Hi Guys,
Im trying to adapt my code to work so that if the textboxes contain a value then use the values within a query and if they dont then ignore the boxes and carry on. How would I go about this? Would it be done by using some kind of not null statement? Im kinda guessing so help is appreciated.
Current code is below:
Code:
Option Compare Database
Private Sub TotalHoursOk_btn_Click()
Dim sProjectRef As String
Dim sTotalhours As String
Dim MySQL As String
Dim sGroupID As Integer
Dim sUserID As String
Dim sUser As String
sUser = Me.CurrentUser
sUserID = "Forms![TimesheetForm]![LoggedInUser]"
sGroupID = DLookup("DepGroupID", "UserNames_tbl", "[sUser]=" & sUserID)
If Me.StartDate_totalhours_txtbox And Me.EndDate_totalhours_txtbox = Null Then
If Me.ProjectRef_txtbox = "" Or IsNull(Me.ProjectRef_txtbox) Then
MsgBox "Please Enter a Project Number"
Else
If Me.TotalHours_Combo = "" Or IsNull(Me.TotalHours_Combo) Then
MsgBox "Please Select from the drop down list"
End If
Select Case Me.TotalHours_Combo
Case "All Employees"
If sGroupID = "2" Then
MySQL = "Select * From TimesheetTable WHERE [ProjectRef] LIKE '*" & Me.ProjectRef_txtbox & "*'"
QDef (MySQL)
Else
MsgBox "You are only allowed to query your own hours, change your selection to current user", vbInformation
End If
Me.TotalHours_Combo.SetFocus
Case "Current User"
MySQL = "Select * From TimesheetTable WHERE [ProjectRef] LIKE '*" & Me.ProjectRef_txtbox & "*' AND [sUser]=sUser"
QDef (MySQL)
End Select
End If
Else
'Do I then repeat the steps if the values are not null? Or am I going about it incorrectly?
End Sub
Thanks