abenitez77
IS-IT--Management
I want to run this query to see if i have any records come up:
SQLRecID_Match = "Select RecID, CurrentUser, DateEntered From dbo.tbl_AR_CurrentUsers As CU"
SQLRecID_Match = SQLRecID_Match & " Inner Join tbl_AR_" & Cmb_ClientName & "_" & strUserID & " As AR"
SQLRecID_Match = SQLRecID_Match & " ON CU.RecID = AR.RecID"
strConnection = "ODBC;DRIVER={SQL Server};SERVER=" & strSQLServer & ";DATABASE=" & strSQLDatabase & ";TRUSTED_CONNECTION=Yes;" '"Toys_2008_TPR;TRUSTED_CONNECTION=Yes;"
Call SQL_PassThrough(strConnection, SQLRecID_Match, strQueryName)
If no records come up, then I want to send an insert statement to sql server, otherwise a Select statement to return a recordset to access.
I can send the code above via passthru...but how do evaluate whether records matched? so i can then create my if in access...
below is my passthru function:
Function SQL_PassThrough(ByVal ConnectionString As String, _
ByVal SQL As String, _
Optional ByVal QueryName As String)
Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef
Set dbs = CurrentDb
Set qdf = dbs.CreateQueryDef
With qdf
.Name = QueryName
.Connect = ConnectionString
.SQL = SQL
.ReturnsRecords = (Len(QueryName) > 0)
If .ReturnsRecords = False Then
.Execute
Else
If Not IsNull(dbs.QueryDefs(QueryName).Name) Then dbs.QueryDefs.Delete QueryName
dbs.QueryDefs.Append qdf
End If
.Close
End With
Set qdf = Nothing
Set dbs = Nothing
End Function
SQLRecID_Match = "Select RecID, CurrentUser, DateEntered From dbo.tbl_AR_CurrentUsers As CU"
SQLRecID_Match = SQLRecID_Match & " Inner Join tbl_AR_" & Cmb_ClientName & "_" & strUserID & " As AR"
SQLRecID_Match = SQLRecID_Match & " ON CU.RecID = AR.RecID"
strConnection = "ODBC;DRIVER={SQL Server};SERVER=" & strSQLServer & ";DATABASE=" & strSQLDatabase & ";TRUSTED_CONNECTION=Yes;" '"Toys_2008_TPR;TRUSTED_CONNECTION=Yes;"
Call SQL_PassThrough(strConnection, SQLRecID_Match, strQueryName)
If no records come up, then I want to send an insert statement to sql server, otherwise a Select statement to return a recordset to access.
I can send the code above via passthru...but how do evaluate whether records matched? so i can then create my if in access...
below is my passthru function:
Function SQL_PassThrough(ByVal ConnectionString As String, _
ByVal SQL As String, _
Optional ByVal QueryName As String)
Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef
Set dbs = CurrentDb
Set qdf = dbs.CreateQueryDef
With qdf
.Name = QueryName
.Connect = ConnectionString
.SQL = SQL
.ReturnsRecords = (Len(QueryName) > 0)
If .ReturnsRecords = False Then
.Execute
Else
If Not IsNull(dbs.QueryDefs(QueryName).Name) Then dbs.QueryDefs.Delete QueryName
dbs.QueryDefs.Append qdf
End If
.Close
End With
Set qdf = Nothing
Set dbs = Nothing
End Function