Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.office.developer.outlook.vba
external usenet poster
 
Posts: 3
Default Why won't this code connect to ODBC

This code will take each email and parses out 3 fields and loads the values
into mysql database (shared host)
My parse works fine but I'm not getting a connection.
Anyone see anything?
Is there a way to log database connection errors

Thanks
Steve


Sub gettext()
Dim str As String, i As Long
Dim strOrderNumber As String, strOrderDate As String
Dim strShipToName As String, strShipToAddress As String
Dim strEbayID As String
Dim whereclause As String



'Dim strShipToAddress1 As String, strShipToAddress2 As String
Set MyExplorer = Application.ActiveExplorer
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cnn = New ADODB.Connection

' Set properties of the Connection.
cnn.ConnectionString = "DSN=mailthem mysql;UID=uname;PWD=pass;"
cnn.ConnectionTimeout = 30

' Find out if the attempt to connect worked.
If cnn.State = adStateOpen Then
MsgBox "Welcome to the Demo Database!"
Else
MsgBox "Sorry. No Database Access."
End If


' Open the connection.
cnn.Open
For i = 1 To MyExplorer.CurrentFolder.Items.Count
Set MyItem = MyExplorer.CurrentFolder.Items(i)
str = MyItem.Body


On Error Resume Next
i = InStr(1, str, "Order Number: ") + Len("Order Number: ")
strOrderNumber = Mid(str, i, InStr(i, str, vbCr) - i)

i = InStr(1, str, "Order Date: ") + Len("Order Date: ")
strOrderDate = Mid(str, i, InStr(i, str, vbCr) - i)

' i = InStr(1, str, " ") + Len(" ")
' strEbayID = Mid(str, i, InStr(i, str, vbCr) - i)


'i = InStr(1, str, "Ship To:")
'i = InStr(i, str, " ")
'strShipToName = Trim(Mid(str, i, InStr(i, str, vbCr) - i))
'i = InStr(i, str, vbCr)
'i = InStr(i, str, " ")


'strShipToAddress = Trim(Mid(str, i, InStr(i, str, vbCr) - i))
'i = InStr(i, str, vbCr)
'i = InStr(i, str, " ")
'strShipToAddress = strShipToAddress & vbNewLine & Trim(Mid(str, i,
InStr(i, str, vbCr) - i))
'i = InStr(i, str, vbCr)
'i = InStr(i, str, " ")
'strShipToAddress = strShipToAddress & vbNewLine & Trim(Mid(str, i,
InStr(i, str, vbCr) - i))

whereclause = " where " + ordernum + " NOT IN (Select ordernum from
hom_orders);"
MsgBox strOrderNumber
MsgBox strOrderDate
'MsgBox strShipToName
'MsgBox strShipToAddress
MsgBox strEbayID
query = "Insert into hom_orders (ordernum, orderdate, ebayid) VALUES ("
+ strOrderNumber + "," + _
strOrderDate + "," + strEbayID + ")" + whereclause


'query = "Select * From T_LastTouched Where txt_TicketNumber = '" +
coldigits + "'"
Set rs = cnn.Execute(query)
MsgBox query


'Set rs = Nothing

' Close the connection.

Next i
Set rs = Nothing
cnn.Close
End Sub



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default Why won't this code connect to ODBC

You need

cnn.Ope

before

Cnn.Stat


  #3   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.office.developer.outlook.vba
external usenet poster
 
Posts: 459
Default Why won't this code connect to ODBC

You need to attempt to

' Open the connection.

before you can

' Find out if the attempt to connect worked.

Here's a slight re-write:

On Error Resume Next
cnn.Open
On Error Goto 0
If cnn.State < adStateOpen Then
MsgBox "Sorry. No Database Access."
Exit Sub
End If
MsgBox "Welcome to the Demo Database!"

--

"sjones" wrote in message om...
This code will take each email and parses out 3 fields and loads the values
into mysql database (shared host)
My parse works fine but I'm not getting a connection.
Anyone see anything?
Is there a way to log database connection errors

Thanks
Steve


Sub gettext()
Dim str As String, i As Long
Dim strOrderNumber As String, strOrderDate As String
Dim strShipToName As String, strShipToAddress As String
Dim strEbayID As String
Dim whereclause As String



'Dim strShipToAddress1 As String, strShipToAddress2 As String
Set MyExplorer = Application.ActiveExplorer
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cnn = New ADODB.Connection

' Set properties of the Connection.
cnn.ConnectionString = "DSN=mailthem mysql;UID=uname;PWD=pass;"
cnn.ConnectionTimeout = 30

' Find out if the attempt to connect worked.
If cnn.State = adStateOpen Then
MsgBox "Welcome to the Demo Database!"
Else
MsgBox "Sorry. No Database Access."
End If


' Open the connection.
cnn.Open
For i = 1 To MyExplorer.CurrentFolder.Items.Count
Set MyItem = MyExplorer.CurrentFolder.Items(i)
str = MyItem.Body


On Error Resume Next
i = InStr(1, str, "Order Number: ") + Len("Order Number: ")
strOrderNumber = Mid(str, i, InStr(i, str, vbCr) - i)

i = InStr(1, str, "Order Date: ") + Len("Order Date: ")
strOrderDate = Mid(str, i, InStr(i, str, vbCr) - i)

' i = InStr(1, str, " ") + Len(" ")
' strEbayID = Mid(str, i, InStr(i, str, vbCr) - i)


'i = InStr(1, str, "Ship To:")
'i = InStr(i, str, " ")
'strShipToName = Trim(Mid(str, i, InStr(i, str, vbCr) - i))
'i = InStr(i, str, vbCr)
'i = InStr(i, str, " ")


'strShipToAddress = Trim(Mid(str, i, InStr(i, str, vbCr) - i))
'i = InStr(i, str, vbCr)
'i = InStr(i, str, " ")
'strShipToAddress = strShipToAddress & vbNewLine & Trim(Mid(str, i,
InStr(i, str, vbCr) - i))
'i = InStr(i, str, vbCr)
'i = InStr(i, str, " ")
'strShipToAddress = strShipToAddress & vbNewLine & Trim(Mid(str, i,
InStr(i, str, vbCr) - i))

whereclause = " where " + ordernum + " NOT IN (Select ordernum from
hom_orders);"
MsgBox strOrderNumber
MsgBox strOrderDate
'MsgBox strShipToName
'MsgBox strShipToAddress
MsgBox strEbayID
query = "Insert into hom_orders (ordernum, orderdate, ebayid) VALUES ("
+ strOrderNumber + "," + _
strOrderDate + "," + strEbayID + ")" + whereclause


'query = "Select * From T_LastTouched Where txt_TicketNumber = '" +
coldigits + "'"
Set rs = cnn.Execute(query)
MsgBox query


'Set rs = Nothing

' Close the connection.

Next i
Set rs = Nothing
cnn.Close
End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Connect.UpdateToolbars? Alexdfw Excel Discussion (Misc queries) 0 May 18th 10 04:18 PM
Connect Two Cells Freshman Excel Worksheet Functions 3 May 20th 08 05:42 PM
How do I connect two worksheets together? ThunderStorm Studio Excel Discussion (Misc queries) 7 February 18th 08 12:46 PM
How to connect to database? Eric Excel Worksheet Functions 3 July 25th 07 12:55 PM
Excel-SQL Connect Michael Schreiber Excel Programming 6 November 13th 03 01:18 PM


All times are GMT +1. The time now is 01:54 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"