I'm trying to right a function to pull data from stand alone tables. This is what i've got so far but it doen't seem to work. I'm trying to pull from a text field.
P.S. For specific reasons i cannot link to these tables.
'''''''''''''''''''''''
These are set on another form
Set gdbs = OpenDatabase("network/path"
strTable$ = "qry_Dates"
strWhere$ = "[Login_Check_No] = '" & CurrentUsername & "'"
'''''''''''''''''''''''
Public Function SQLRecordFindFromDBS&(strFind$, strTable$, Optional strWhere$)
On Error GoTo Error_Handler
Dim rs As Recordset, strSQL$
If gdbs Is Nothing Then
MsgBox "Reference to database missing!", vbCritical, "Error"
Exit Function
End If
strSQL$ = "SELECT (" & strFind$ & "
FROM " & strTable$
If Len(strWhere$) Then strSQL$ = strSQL$ & " WHERE (" & strWhere$ & "
"
Set rs = gdbs.OpenRecordset(strSQL$ & ";", dbOpenSnapshot, dbReadOnly)
'If no recordset was returned
If rs Is Nothing Then GoTo Exit_Here
With rs
'If recordset was returned, return a count of the specifiled field
'I think this is where the problem is
If Not .BOF And Not .EOF Then SQLRecordFindFromDBS& = .Fields(0)
'Close the recorset
.Close
End With
Exit_Here:
On Error Resume Next
Set rs = Nothing
Exit Function
Error_Handler:
' MsgBox "(" & Err & "
" & Err.Description, vbCritical, "Error"
Err.Clear
Resume Exit_Here
End Function
P.S. For specific reasons i cannot link to these tables.
'''''''''''''''''''''''
These are set on another form
Set gdbs = OpenDatabase("network/path"
strTable$ = "qry_Dates"
strWhere$ = "[Login_Check_No] = '" & CurrentUsername & "'"
'''''''''''''''''''''''
Public Function SQLRecordFindFromDBS&(strFind$, strTable$, Optional strWhere$)
On Error GoTo Error_Handler
Dim rs As Recordset, strSQL$
If gdbs Is Nothing Then
MsgBox "Reference to database missing!", vbCritical, "Error"
Exit Function
End If
strSQL$ = "SELECT (" & strFind$ & "
If Len(strWhere$) Then strSQL$ = strSQL$ & " WHERE (" & strWhere$ & "
Set rs = gdbs.OpenRecordset(strSQL$ & ";", dbOpenSnapshot, dbReadOnly)
'If no recordset was returned
If rs Is Nothing Then GoTo Exit_Here
With rs
'If recordset was returned, return a count of the specifiled field
'I think this is where the problem is
If Not .BOF And Not .EOF Then SQLRecordFindFromDBS& = .Fields(0)
'Close the recorset
.Close
End With
Exit_Here:
On Error Resume Next
Set rs = Nothing
Exit Function
Error_Handler:
' MsgBox "(" & Err & "
Err.Clear
Resume Exit_Here
End Function