Link to home
Start Free TrialLog in
Avatar of igotnosmoke
igotnosmoke

asked on

Compile error: User-defined type not defined

Hi im recieving the Compile Error listed above. Im fairly new to VB and it is doing my head in....

Im wondering whether someone can go through and fix what ive done wrong. Its just a simple connection to a database called MIRO.mdb and a form (frmSalesPerson.frm) that accesses records "SalesPersonNo" and "SalesPersonName".

the compile error highlights this particular line
"Private mrsSalesPerson As New ADODB.Recordset"

---------------------------------------------------------

Here is the code i have for frmSalesPerson:

Option Explicit
'** Declare module-level variables
Private mrsSalesPerson As New ADODB.Recordset
Private mstMode As String
Private mcoControl As Control
Private mstSalesPersonNo As String

Private Sub cmdAdd_Click()

mstMode = "Add"
lblHeading.Caption = "Add Sales Person"
Call ClearData
Call HideViewButtons
mstSalesPersonNo = txtSalesPersonNo.Text
Call SetActiveControls
cmdSave.Visible = True
cmdCancel.Visible = True

End Sub

Private Sub cmdEdit_Click()

mstMode = "Edit"
lblHeading.Caption = "Edit Sales Person"
Call SetActiveControls
Call HideViewButtons
mstSalesPersonNo = txtSalesPersonNo.Text

End Sub

Private Sub cmdDelete_Click()

Dim pstDeleteMsg As String
Dim pinResponse As Integer
Dim pstDeleteSalesPersonSQL As String
Dim prsDeleteSalesPerson As New ADODB.Recordset
pstDeleteMsg = "Are you sure that you want to remove this Sales Person?"
pinResponse = MsgBox(pstDeleteMsg, vbCritical + vbYesNo, "Delete Sales Person?")
If pinResponse = vbYes Then

With mrsSalesPerson

    !SalesPersonStatus = False
   
    .Update
   
    .Requery
   
End With
Call DisplayData
End If

End Sub

Private Sub cmdFirst_Click()
mrsSalesPerson.MoveFirst
Call DisplayData
End Sub

Private Sub cmdLast_Click()
mrsSalesPerson.MoveLast
Call DisplayData
End Sub

Private Sub cmdClose_Click()
frmItemDetails.Show 1
End Sub

Private Sub cmdPrevious_Click()
'Move the pointer to the previous record if not already at the Begining of the File.
mrsSalesPerson.MovePrevious
If mrsSalesPerson.BOF Then
    MsgBox "You are at the Start of the  Sales Persons records.", vbCritical, "Begining of table"
    mrsSalesPerson.MoveFirst
Else
    Call DisplayData
End If
End Sub

Private Sub cmdSearch_Click()
'Makes the  Sales Person search frame visible on the screen
Call HideViewButtons
fraSalesPersonSearch.Visible = True
cmdSave.Visible = False
cmdCancel.Visible = False
Call ClearData

End Sub

Private Sub cmdMainMenu_Click()
'Close frmSalesPerson before returning to frmMainMenu, which has remained open.
Unload frmSalesPerson
Set frmSalesPerson = Nothing
End Sub

--------------------------------------------------------
and here is my module form:

Option Explicit
'**Declare a New ADODB connection object variable
Public gcnMIRO As New ADODB.Connection

Sub Main()
'**Set the connection object to the database once only in a project
If Left(App.Path, 2) <> "\\" Then
    ChDrive App.Path
End If
ChDir App.Path
'**Open the connection to the database
gcnMIRO.Open "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = MIRO.mdb"
frmSalesPerson.Show
End Sub

Sub CloseConnection()
gcnMIRO.Close
Set gcnMIRO = Nothing
End Sub
----------------------------------------
Thanks for your help,
Spaz
ASKER CERTIFIED SOLUTION
Avatar of ADSaunders
ADSaunders

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of qing02051981
qing02051981

Under Project --> References
Check Microsoft ActiveX Date Objects 2.0 Library. It is more than enough.