I think this is a silly question, because I think I did it right. However, the variable txtDept returns null. strDept returns a correct value. All I want to do is run the function and assign its returned value to a variable.
Thanks!
Code:
Private Sub txtLaborHours_AfterUpdate()
Dim txtEmpID As String
txtEmpID = Forms!frmTimeCard.txtEmpID.Value
Dim txtDept As String
txtDept = GetDeptStatus(txtEmpID)
Debug.Print ("txtDept: " & txtDept)
txtNotes.SetFocus
Select Case txtDept
Case "ME", "EE", "AS", "MA", "HYD"
If Len(txtNotes.Text) = 0 And cboBillable.Value = "I" Then
txtLaborHours.Value = Null
txtNotes.SetFocus
Me.Refresh
MsgBox "You must enter Notes on non-billable activity before Time. "
End If
End Select
End Sub
Code:
Private Function GetDeptStatus(strEmpID As String) As String
' Added 9/22/15
' This sub gets the Shop Supervisor Status from Vantage to determine which controls to show or hide
' Dimension variables
Dim sqlGetDeptStatus As String
Dim rsGetDeptStatus As adodb.recordset
' Set variables
Set rsGetDeptStatus = New adodb.recordset
Debug.Print ("strEmpID: " & strEmpID)
' Create Query
sqlGetDeptStatus = "SELECT dbo_empbasic.jcdept " & _
"FROM dbo_empbasic " & _
"WHERE dbo_empbasic.empid = '" & strEmpID & "' "
Debug.Print ("sqlGetDeptStatus: " & sqlGetDeptStatus)
' Open the recordset and populate the form
rsGetDeptStatus.Open sqlGetDeptStatus, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
Dim strDept As String
If Not rsGetDeptStatus.EOF Then
strDept = rsGetDeptStatus.Fields("jcdept")
Else
strDept = ""
End If
rsGetDeptStatus.Close
Set rsGetDeptStatus = Nothing
strDept = strDept
Debug.Print ("strDept: " & strDept)
End Function