Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieving Data from Another Table

Status
Not open for further replies.

ryan1

Programmer
May 15, 2002
106
0
0
US
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top