sub or function not defined

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jugal
    New Member
    • Jan 2009
    • 1

    sub or function not defined

    hi guys,im a newbie here.. i have a piece of coding.. but i get an error,pls help,its for my final project...:(
    i have highlighted where i get an error.. pls help. if u must know i got the source code online and modified it to suit my requirements.
    Code:
     
    Option Explicit
    Dim db As Database
     
    Dim rs As Recordset
     
    Private Sub Form_Load()
     
    On Error GoTo ErrHandler
    Set db = OpenDatabase(App.Path & "\sad.mdb")
    Set rs = db.OpenRecordset("supplier", dbOpenDynaset)
    Exit Sub
    ErrHandler:
    Dim ErrNum, ErrDesc, ErrSource
    ErrNum = Err.Number
    ErrDesc = Err.Description
    ErrSource = Err.Source
    MsgBox "Error# = " & ErrNum & vbCrLf & "Description = " & ErrDesc & vbCrLf & "Source = " & ErrSource, vbCritical + vbOKOnly, "Program Error!"
    Err.Clear
    Exit Sub
     
    End Sub
     
    [B]Private Sub cmd_add_Click()[/B]
    On Error GoTo ErrHandler
     
    Dim SupplierID, Name, Address
    If txtID.Text = "" And txtName.Text = "" And _
    txtAddress.Text = "" Then
     
    MsgBox "You must enter information in for at least the supplier" _
    , vbOKOnly + vbCritical, "Data Required"
    ClearForm
     
    Exit Sub
    End If
    SupplierID = Encode(txtID.Text)
    Name = Encode(txtName.Text)
    Address = Encode(txtAddress.Text)
    With rs
    .AddNew
    !SupplierID = ID
    !Name = Name
    !Address = Address
     
    .Update
    End With
    ClearForm
    GetEntries
    Exit Sub
    End Sub
     
     
    Private Sub Form_Unload(Cancel As Integer)
    rs.Close
    db.Close
    End Sub
    Last edited by debasisdas; Jan 27 '09, 09:26 AM. Reason: added code tags
  • smartchap
    New Member
    • Dec 2007
    • 236

    #2
    Dear Jugal

    In cmd_add click event write code for label ErrHandler.
    Write code for ClearForm and GetEntries. I think ur code will be alright.

    Always believe in God.

    Comment

    • Keithuk
      New Member
      • Nov 2006
      • 10

      #3
      Welcome to Bytes jugal.

      Originally posted by jugal
      i have highlighted where i get an error.. pls help.[code]
      Option Explicit
      Dim db As Database

      Dim rs As Recordset

      Private Sub Form_Load()

      On Error GoTo ErrHandler


      Exit Sub
      ErrHandler:
      Dim ErrNum, ErrDesc, ErrSource
      ErrNum = Err.Number
      ErrDesc = Err.Description
      ErrSource = Err.Source
      MsgBox "Error# = " & ErrNum & vbCrLf & "Descriptio n = " & ErrDesc & vbCrLf & "Source = " & ErrSource, vbCritical + vbOKOnly, "Program Error!"
      Err.Clear
      Exit Sub

      End Sub

      Private Sub cmd_add_Click()
      On Error GoTo ErrHandler

      Dim SupplierID, Name, Address
      I see no error line hightlighted.

      I only see what smartchap has picked up you are using an error trap but there is no ErrHandler in that Sub. You have stated and shown it in Form_Load.

      Also when you declare variables use the correct type

      Dim SupplierID, Name, Address

      All those will be Variants because you have stated anything otherwise.

      Dim SupplierID As Long, Name As String, Address As String

      I would avoid using Name as a variable because Name is a Keyword in VB.

      I'm betting again your another VB use that isn't using Option Explicit. If you don't know what it means or how to set it up then just ask.

      Comment

      Working...