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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

error message - "user-defined type not defined"??

Status
Not open for further replies.

miscluce

MIS
Oct 4, 2007
149
US
can someone tell me what to look for here or explain this better?
Usually this happens when I forget to delete the record source. I am using VB code to connect to the db and open/set new record set during a form load event.

errro help message"
This error occurs when an event has failed to run because Microsoft Office Access cannot evaluate the location of the logic for the event. For example, if the OnOpen property of a form is set to =[Field], this error occurs because Access expects a macro or event name to run when the event is fired."
 
Show us the line of code where the error occurs. In that line, you are almost certainly referencing either:
1. A control that doesn't exist (misspelled)
2. A variable that's not declared
3. An object variable that has not been initialized


 
yeah, I thought that too. maybe I am overlooking something.

Private Sub Form_Load()
strConnection = "Provider=sqloledb;Data Source=MISFS;" & "Integrated Security=SSPI;Initial Catalog=Sample"

'create a new connection instance and open it using the connection string
Set cnDb = New ADODB.Connection
cnDb.Open strConnection

'create a new instance of a recordset
Set rsNames = New ADODB.Recordset

'set various properties of the recordset
With rsNames
'specify a cursortype and lock type that will allow updates
.CursorType = adOpenKeyset
.CursorLocation = adUseClient
.LockType = adLockBatchOptimistic
'open the recordset based on tbl table using the existing connection
.Open "tblName", cnDb
'disconnect the recordset
.ActiveConnection = Nothing
'sort the recordset
.Sort = "fldLastName, fldFirstName"
End With

'if the recordset is empty
If rsNames.BOF And rsNames.EOF Then
Exit Sub
Else
'move to the first record
rsNames.MoveFirst
'populate the controls on the form
'Call PopulateControlsOnForm
End If

'close the database connection and release it from memory
cnDb.Close
Set cnDb = Nothing

End Sub
 
I solved this. I forgot to add the reference(MS active X objects library).

 
How do you go about adding a library reference? I'm having this same problem with FileDialog.
 
I can see the FileDialog in my Object browser, but I can't seem to use it, and the reference option in tools is greyed out, so I can explore adding new references.
 
open up your visual basic editor in Access and in the main menu go to tools>reference
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top