NigelShaw
Registered User.
- Local time
- Today, 11:31
- Joined
- Jan 11, 2008
- Messages
- 1,575
Hi,
a quick SQL question. i have a code and everything set up to look through my SQL server and collect fields. the code is -
from access, i need to create a table if a table doesnt exist and add the records to it by looping through it. my current code is-
Pretty desperate for once in my life LOL
any help greatly appreciated people
Nidge
a quick SQL question. i have a code and everything set up to look through my SQL server and collect fields. the code is -
Code:
SELECT fldCellPhone, fldFirstName, fldLastName, fldTotalVisits, fldLastVisit, fldFirstEmployeeName
FROM tblClients
WHERE (fldTotalVisits = 1) AND (fldFirstEmployeeName = 'employee' ) AND (fldLastVisit < CONVERT(DATETIME, '2010-05-20 00:00:00', 102))
from access, i need to create a table if a table doesnt exist and add the records to it by looping through it. my current code is-
Code:
Sub SQLCollectData()
'##set up your variables##
Dim m_oRecordset As ADODB.Recordset
Dim m_sConnStr As String
Dim sSQL As String
Dim oConnection1 As ADODB.Connection
Dim strSource As String
Dim strSourceEnviron As String
Dim strSourceServer As String
Dim strCatalog As String
Dim strGetData As String
Dim strAddString As String
Dim intGetNumber As Integer
Dim db As DAO.Database
Dim rss As DAO.Recordset
Dim qdf As DAO.QueryDef
'##collect environment data##
strSourceEnviron = VBA.Environ("computername")
strSourceServer = "\CMJ"
strSource = strSourceEnviron & strSourceServer
strCatalog = "SalonIris"
'##create connection to SQL server##
m_sConnStr = "Provider='SQLOLEDB';Data Source='" & strSource & "';" & _
"Initial Catalog='" & strCatalog & "';Integrated Security='SSPI';"
Set oConnection1 = New ADODB.Connection
oConnection1.CursorLocation = adUseClient
oConnection1.Open m_sConnStr
'##Create specific SQL statement##
'sSQL = "SELECT fldFirstName, fldLastName, fldActive " & _
'"FROM tblEmployees WHERE fldActive = 1"
'##Create specific SQL statement##
sSQL = "SELECT fldFirstName, fldLastName, fldDateScheduled, fldCheckedIn, fldCNClosed " & _
"FROM tblTicketsSummary WHERE fldCheckedIn <> 0"
'WHERE fldDateScheduled = CONVERT(DATETIME, CONVERT(varChar, GetDate(), 101))" & _
'" AND fldCheckedIn <> 0 AND fldCNClosed = 0"
'##Run SQL##
Set m_oRecordset = New ADODB.Recordset
m_oRecordset.Open sSQL, oConnection1, adOpenStatic, _
adLockBatchOptimistic, adCmdText
m_oRecordset.MarshalOptions = adMarshalModifiedOnly
Set m_oRecordset.ActiveConnection = Nothing
'##count records for testing##
With m_oRecordset
j = .RecordCount
'##Set up loop through records##
For i = 1 To j
'##collect data from table or query##
strAddString = "@textmagic.co.uk" 'set up the mobile number for text alert
strGetData = !fldFirstName
strGetData = strGetData & " " & !fldLastName
intGetNumber = !fldCellNumber
'###I NEED TO CHECK FOR A TABLE AND CREATE ONE IF IT DOESNT EXIST HERE THEN ADD THE DATA COLLECTED INTO THE FIELDS ###
'MsgBox strGetData
.MoveNext
Next i
End With
'##clean up##
m_oRecordset.Close
oConnection1.Close
Set m_oRecordset = Nothing
Set oConnection1 = Nothing
Exit Sub
Pretty desperate for once in my life LOL
any help greatly appreciated people
Nidge