Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Type mismatch run-error

Status
Not open for further replies.

autoIT

IS-IT--Management
May 10, 2006
68
US
ok i know this is a common freakin question, but i've been at this all day and i can't figure this out. I am including code from a db I wrote. it is the general declaratins and the form load page. When I dedug the error handler kicks in at the line that defines the recordset. I have tried it 2 different ways, and both ways get an error. I know it could be my connection definaition as well, but i can't figure it out These are the 2 ways i tried:

Set rs = New ADODB.Recordset(seen below)
rs.ActiveConection = cn


Option Compare Database
Option Explicit
Dim cn As Connection
Dim rs As New ADODB.Recordset
Dim DelConfirm As Integer
Dim ctl As Control



'sets varibales for connection and recordset, opens connection to table, call fillcontrols procedure that will fill info into textboxes

Private Sub Form_Load()
For Each ctl In Controls
If TypeOf ctl Is TextBox Then
ctl.BackColor = vbWhite
End If
Next



cmdInsert.Visible = False
cmdNext.Visible = True
cmdPrev.Visible = True
cmdNew.Visible = True

Set cn = CurrentProject.Connection
Set rs = New ADODB.Recordset

rs.Open "tblEmpInfo", cn, adOpenDynamic, adLockOptimistic, adCmdTable

FillControls
End Sub
 
autoIT,
Unless you really need it I would just drop the connection object since it's only needed to open the recordset and has the same attributes as your current project.
Code:
'Global Declarations
Dim rs As ADODB.Recordset

'Event Handler
Private Sub Form_Open(Cancel As Integer)
Set rs = New ADODB.Recordset
rs.Open "tblEmpInfo", [b]CurrentProject.Connection[/b]...

Hope this helps,
CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
Dim cn As [!]ADODB.[/!]Connection

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top