CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Guest

    Connection Ojbect

    Can anyone help me with the following code? I'm getting, "Invalid use of New keyword", when I try to run it. Thanks so much for your help!

    Private Sub cmdSubmit_Click()
    Dim cnBusinessRule As Connection
    Dim sSQL As String
    Set cnBusinessRule = New Connection

    'Establish a connection
    With cnBusinessRule
    .Provider = "Microsoft.Jet.OLEDB.3.51"
    .ConnectionString = "User ID = sa; password=;" & _
    "Data Source=C:\BusinessRules\Database\BusinessRule.mdb;" & _
    "Initial Catalog=BusinessRule"
    .Open
    End With
    sSQL = "INSERT INTO GOV_AUTHORITY(Name, Category) " & _
    "VALUES (txtName, cmbCategory)"

    cnBusinessRule.Execute sSQL
    cnBusinessRule.Close
    Set cnBusinessRule = Nothing
    End Sub



  2. #2
    Join Date
    Jul 2000
    Location
    UK
    Posts
    37

    Re: Connection Ojbect

    Try:
    private Sub cmdSubmit_Click()
    Dim cnBusinessRule as new Adodb.Connection
    Dim sSQL as string

    set cnBusinessRule = adodb.Connection

    'Establish a connection
    With cnBusinessRule
    .Provider = "Microsoft.Jet.OLEDB.3.51"
    .ConnectionString = "User ID = sa; password=;" & _
    "Data Source=C:\BusinessRules\Database\BusinessRule.mdb;" & _
    "Initial Catalog=BusinessRule"
    .Open
    End With
    sSQL = "INSERT INTO GOV_AUTHORITY(Name, Category) " & _
    "VALUES (txtName, cmbCategory)"

    cnBusinessRule.Execute sSQL
    cnBusinessRule.Close
    set cnBusinessRule = nothing
    End Sub




    Regards



    Anne Wright
    Wright Computing

  3. #3
    Guest

    Re: Connection Ojbect

    Anne,

    Thanks for your reply...I've tried with your code and am now getting, "Method or data member not found", message. In order to use the ADO connection, do I need to bind it to the form before I can use it?

    Thanks again Anne.


  4. #4
    Join Date
    Oct 1999
    Location
    MD, USA
    Posts
    169

    Re: Connection Ojbect

    Try:

    private Sub cmdSubmit_Click()
    Dim cnBusinessRule as new Adodb.Connection
    Dim sSQL as string
    'Establish a connection
    With cnBusinessRule
    .Provider "Microsoft.Jet.OLEDB.3.51"
    .ConnectionString = "User ID = sa; password=;" & _ "Data Source=C:\BusinessRules\Database\BusinessRule.mdb;" & _ "Initial Catalog=BusinessRule"
    .Open End With sSQL = "INSERT INTO GOV_AUTHORITY(Name, Category) " & _ "VALUES (txtName, cmbCategory)" cnBusinessRule.Execute sSQL cnBusinessRule.Close
    set cnBusinessRule = nothing
    End Sub






  5. #5
    Guest

    Re: Connection Ojbect

    Hi.

    I've tried with your code and I now get a runtime error on the .Open statement.

    Any ideas?

    Thanks again.
    Morgan


  6. #6
    Join Date
    Oct 1999
    Location
    MD, USA
    Posts
    169

    Re: Connection Ojbect

    There could be many reasons for this..
    Since there is no error on your ADODB object model instantiation statments now this tells me that instantiation is fine.
    Runtime errors could be due to the mdb file not being in the path specified..
    Step thru your code and try to figure out the error

    best of luck!!



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured