Link to home
Start Free TrialLog in
Avatar of Fordraiders
FordraidersFlag for United States of America

asked on

outlook custom form with command button not executing code

Outlook 2010.
vb script editor problem/issues

Custom form
Page "Survey" (p.2)

I have a command button on a custom  form.

I'm just trying the code out to see if i can get anything to execute. after pressing the command button.

I always get an error on this line:
Dim cnn As ADODB.Connection



Sub CommandButton2_Click()
  
Dim cnn As ADODB.Connection
   Set cnn = New ADODB.Connection

   ' Open a Connection using an ODBC DSN named "Pubs".
   cnn.Open "ss_program_workflow", "webuser", "zwebuserprd"

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

   ' Close the connection.
   cnn.Close
End Sub

Open in new window



The only thing i can get to work is simple: hello world

Sub CommandButton2_Click()
  msgbox "Hello World"
End Sub


Thanks
fordraiders
Avatar of Najam Uddin
Najam Uddin
Flag of United States of America image

Have you added reference Microsoft ActiveX Data Object library?
Avatar of Fordraiders

ASKER

yes
What is the error you get?
expected end of statement
line 21

Remember i'm in "Script Editor" of the Custom Form

and line 21 is this
Dim cnn As ADODB.Connection
ok..

i did this:

Dim cnn
   Set cnn = New ADODB.Connection

got past my previous error:

got the msgbox

but now getting :
class not defined  ADODB
ok.

got it to work with this:
Dim cnn  
   Set cnn = CreateObject("ADODB.Connection")

Now, how do i declare recordset?
ASKER CERTIFIED SOLUTION
Avatar of Najam Uddin
Najam Uddin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ok i wil try it out..

It will take a few...
I will get back.,
Thanks
Dim cnn
   Set cnn = CreateObject("ADODB.Connection")

Dim rs1

dim connectstring
Dim tp

   ' Open a Connection using an ODBC DSN named "SS PROGRAM WORKFLOW".
 
cnn.open "PROVIDER=SQLOLEDB;DATA SOURCE=dddddd025.com;UID=xxxxx;PWD=xxxxx;DATABASE=program_workflow "

sQuery = "Select * from temp_proposal_survey_results;"
 
 set rs1 = CreateObject("ADODB.Recordset")
 
              rs1.open sQuery, cnn, adOpenDynamic

tp =  rs1.recordcount

if tp = "" then
msgbox "hello recordcount"
end if

   ' Close the connection.
   cnn.Close

Not getting any errors but,,..not opening the recordset  either ??
finally...got this to work.
Const adUseClient = 3

Dim cnn
   Set cnn = CreateObject("ADODB.Connection")
Dim rs1
Dim connectstring
Dim tp
Dim q
   ' Open a Connection using an ODBC DSN named "SS PROGRAM WORKFLOW".
cnn.CursorLocation = adUseClient

cnn.open "PROVIDER=SQLOLEDB;DATA SOURCE=XXXXX.XXer.com;UID=XXXXXXuser;PWD=XXXXXuserprd;DATABASE=workflow"

sQuery = "Select * from [survey_results]"
Set rs1 = CreateObject("ADODB.Recordset")
rs1.open sQuery, cnn
rs1.MoveFirst
tp =  rs1.recordcount
If tp = 1 Then
MsgBox "One Record"
End if
   ' Close the connection.
   cnn.Close
Set cnn = nothing
thanks