Command Button Click

G

Guest

I want to assign the following code to a button on my Excel 2003 spreadsheet.
When I click the button, I receive a Microsoft Visual Basic Error "Compile
Error: User-defined type not defined"

Dim Con As New ADODB.Connection
Dim Cmd As New ADODB.Command
Dim Cmd2 As New ADODB.Command
Dim Rs As ADODB.Recordset

Con.Open "DSN=KIAMOTOR;"
Set Cmd.ActiveConnection = Con
Cmd.CommandText = "SELECT * FROM PTFGRPP"

Thanks in advance for the help.
 
G

Guest

Did you make a reference to "Microsoft ActiveX Data Objects ?.? Library"
Tools -> References in the VBE
You need that if you want to use ADODB
 
G

Guest

I added the reference and am no longer receiving the error but clicking the
button does not pull down any recrods to the spreadsheet.
 
G

Guest

Please post all of your code... When you look at your recordset (rs) is there
anything in it?
 
G

Guest

This is the code I have behind my command button.

Private Sub CommandButton2_Click()
Dim Con As New ADODB.Connection
Dim Cmd As New ADODB.Command
Dim Cmd2 As New ADODB.Command
Dim Rs As ADODB.Recordset

Con.Open "DSN=KIAMOTOR;"
Set Cmd.ActiveConnection = Con
Cmd.CommandText = "SELECT * FROM PTFGRPP"
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top