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
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