Invalid Outside Procedure

hascons

Registered User.
Local time
Yesterday, 17:59
Joined
Apr 20, 2009
Messages
58
Hello
I have the following code to populate an unbound form. I keep getting the Error Message (Invalid Outside Procedure).

Does anybody know why


Option Compare Database

Private rstEmployees As ADODB.Recordset
Private cnn As ADODB.Connection

Private Sub Form_Open(Cancel As Integer)
Dim str As String
Dim intReturn As Integer
str = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=c:\Company\Company DataBase\Employees.accdb"

Set cnn = New ADODB.Connection
cnn.Open (str)

Set rstEmployees = New ADODB.Recordset
rstEmployees.Open "Employees", _
ActiveConnection:=cnn, _
CursorType:=adOpenForwardOnly, _
LockType:=adLockOptimistic, _
Options:=adCmdTableDirect

'Set rstEmployees = New ADODB.Recordset
'rstEmployees.CursorType = adOpenKeyset
'rstEmployees.LockType = adLockPessimistic
'rstEmployees.Open "[Employees]", CurrentProject.Connection, , , adCmdTable

intReturn = UnBoundDisplay(Me, rstEmployees)

End Sub
Function UnBoundDisplay(frm As Form, frmRS As Recordset) As Integer
Dim ctlName As String
Dim lngReturn As Long
Dim x As Integer

On Error GoTo Display_Err

frmRS.MoveFirst

'Cycle Through the Recordset Setting the Value of Each Control On Form
For x = 0 To frmRS.Fields.Count - 1
ctlName = frmRS.Fields(x).Name
frm.Controls(ctlName).Value = frmRS.Fields(x).Value
Next x

Display_End
Exit Function

Display_Err
'If there's an error switch to the error handling procedure
lngReturn = ErrorRoutine(0)
GoTo Display_End
End Function
 
Private rstEmployees As ADODB.Recordset
Private cnn As ADODB.Connection

Change to Dim frm Private see if that works.
 
Hello DCrake

I Changed the Private to Dim as you suggested Now I get a Type Mismatch Error. I've Pasted the Code back to clarify where.

Dim rstEmployees As ADODB.Recordset
Dim cnn As ADODB.Connection


Private Sub Form_Open(Cancel As Integer)
Dim intReturn As Integer
Dim str As String

Set rstEmployees = New ADODB.Recordset
rstEmployees.CursorType = adOpenKeyset
rstEmployees.LockType = adLockPessimistic
rstEmployees.Open "[Employees]", CurrentProject.Connection, , , adCmdTable



intReturn = UnBoundDisplay(Me, rstEmployees) ****Get Type MisMatch Here

End Sub

Function UnBoundDisplay(frm As Form, frmRS As Recordset) As Integer
Dim ctlName As String
Dim lngReturn As Long
Dim x As Integer

On Error GoTo Display_Err

frmRS.MoveFirst

'Cycle Through the Recordset Setting the Value of Each Control On Form
For x = 0 To frmRS.Fields.Count - 1
ctlName = frmRS.Fields(x).Name
frm.Controls(ctlName).Value = frmRS.Fields(x).Value
Next x

Display_End
Exit Function

Display_Err
'If there's an error switch to the error handling procedure
lngReturn = ErrorRoutine(0)
GoTo Display_End
End Function
 
Hello DCrake

I Changed the Private to Dim as you suggested Now I get a Type Mismatch Error. I've Pasted the Code back to clarify where.

Dim rstEmployees As ADODB.Recordset
Dim cnn As ADODB.Connection


Private Sub Form_Open(Cancel As Integer)
Dim intReturn As Integer
Dim str As String

Set rstEmployees = New ADODB.Recordset
rstEmployees.CursorType = adOpenKeyset
rstEmployees.LockType = adLockPessimistic
rstEmployees.Open "[Employees]", CurrentProject.Connection, , , adCmdTable



intReturn = UnBoundDisplay(Me, rstEmployees) ****Get Type MisMatch Here

End Sub

Function UnBoundDisplay(frm As Form, frmRS As ADODB.Recordset) As Integer
Dim ctlName As String
Dim lngReturn As Long
Dim x As Integer

On Error GoTo Display_Err

frmRS.MoveFirst

'Cycle Through the Recordset Setting the Value of Each Control On Form
For x = 0 To frmRS.Fields.Count - 1
ctlName = frmRS.Fields(x).Name
frm.Controls(ctlName).Value = frmRS.Fields(x).Value
Next x

Display_End
Exit Function

Display_Err
'If there's an error switch to the error handling procedure
lngReturn = ErrorRoutine(0)
GoTo Display_End
End Function

On your function try changing the second argument from Recordset to ADODB.Recordset
 
maybe you cannot pass an ado recordset as an argument

since its already dimmed as a form variable, remove it from the argument list for the unbounddisplay function.

does that help?
 
Gemma-The-Husky

That Solved The Problem Thank You!
 

Users who are viewing this thread

Back
Top Bottom