Write code to programmatically open Access - InfoPath Dev
in

InfoPath Dev

Write code to programmatically open Access

Last post 11-28-2005 11:28 PM by Shyam. 18 replies.
Page 1 of 2 (19 items) 1 2 Next >
Sort Posts: Previous Next
  • 11-15-2005 11:02 AM

    Write code to programmatically open Access

    I'm getting an error of unhandeled exception when I run this code. Does anyone know why this may be happening. Currently have know data connections linked to infopath form. When I click the button , I'd like to link up the Database to view records

    <InfoPathEventHandler(MatchPath:="Button1", EventType:=InfoPathEventType.OnClick)> _
    Public Sub Button1_OnClick(ByVal e As DocActionEvent)


    Dim con As New OleDb.OleDbConnection
    con.ConnectionString= "Provider=Microsoft.Jet.OLEDB.4.0;
    Data Source= C:\GA10605"

    con.Open()

    MsgBox("open")
    con.Close()
    MsgBox("closed")


    End Sub
  • 11-15-2005 11:06 PM In reply to

    Re: Write code to programmatically open Access

    Is C:\GA10605 a DB file or a directory?

    Patrick Halstead [InfoPath MVP]
    InfoPathDev
    Patrick Halstead
    Project Manager at Qdabra
  • 11-16-2005 06:14 AM In reply to

    Re: Write code to programmatically open Access

    It's a Database. I also tried with the .MDB extn attached to it. I guess my real question is , Will this work logically? Could it just be a syntax error or am I trying something Infopath and VB.net are incapable of doing?
  • 11-16-2005 06:54 AM In reply to

    Re: Write code to programmatically open Access

    Hi,

    In that case, replace:
    con.ConnectionString= "Provider=Microsoft.Jet.OLEDB.4.0;
    Data Source= C:\GA10605"
    by:
    con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source= C:\GA10605.mdb"



    Regards,

    Franck Dauché
    InfoPathDev
  • 11-16-2005 07:11 AM In reply to

    Re: Write code to programmatically open Access

    Still doesn't work. Here's the error:

    Request failed.
    at InfoPathProject3.InfoPathProject3.Button1_OnClick(DocActionEvent e)
    at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)
  • 11-16-2005 06:44 PM In reply to

    Re: Write code to programmatically open Access

    Did you escape the \ character? You probably need to have something like C:\\GA10605.mdb or something like that.

    Patrick Halstead [InfoPath MVP]
    InfoPathDev
    Patrick Halstead
    Project Manager at Qdabra
  • 11-16-2005 09:13 PM In reply to

    Re: Write code to programmatically open Access

    - You can open your mdb manually, right? It is not corrupted?
    - You have your reference to System.Data?

    Regards,

    Franck Dauché
    InfoPathDev
  • 11-16-2005 11:02 PM In reply to

    Re: Write code to programmatically open Access

    Are escaped backslashes required for database connection strings?

    Patrick Halstead [InfoPath MVP]
    InfoPathDev
    Patrick Halstead
    Project Manager at Qdabra
  • 11-16-2005 11:12 PM In reply to

    Re: Write code to programmatically open Access

    nope, I don't think backslashes are required....I actually tested the code myself on a VB-based project, and it works fine. That's why I think that Kelly may have an issue with the db itself.

    Franck
  • 11-17-2005 06:18 AM In reply to

    Re: Write code to programmatically open Access

    Let me ask you one question. Do I need to have a main connection thru the Infopath GUI Wizard before attempting to use this code?
    Logically , I would say this code would make the connection. Is that correct?
    I need to view, submit navagate , and add records . The only way I know how to do that is thru coding command btns in vb.net.
    Maybe I'll try a fresh infopath project and see what I can come up with.

    Could you send me a high level overview on how you got yours working. General steps. I can fill in the blanks, thanks!
  • 11-17-2005 06:49 AM In reply to

    Re: Write code to programmatically open Access

    Hi Kelly,

    You open a new VB.Net project, you add a reference to System.Data. You drop 1 button and the form and write the code that you posted, with the connection string on 1 single line. You run and it works.
    If you did that and are still experiencing issues, the only difference between your code and mine would be the database (an Access 2003 DB in my case).

    Regards,

    Franck Dauché
    InfoPathDev
  • 11-17-2005 06:56 AM In reply to

    Re: Write code to programmatically open Access

    I thought I did that , but I'll try try again, Thanks for the instruction and confirmation!
  • 11-17-2005 07:15 AM In reply to

    Re: Write code to programmatically open Access

    I tried again with a fresh template and got the same error. It says system.security exception at the top of the error. Could this be a security setting in the options? I am running access 03 as well.

    error:
    System.Security.SecurityException
    Request failed.
    at InfoPathProject4.InfoPathProject4.btnOne_OnClick(DocActionEvent e)
    at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)
  • 11-17-2005 01:50 PM In reply to

    Re: Write code to programmatically open Access

    OK, did you try with a new fresh simple Access 2003 DB (no password).
    It looks like the error message changed: Security.SecurityException.
    I bet everything is now OK, but your connection string doesn't work because you need to add info to open the GA10605 DB. User may not be Admin, pwd may have been set, etc.

    Regards,

    Franck Dauché
    InfoPathDev
  • 11-17-2005 02:20 PM In reply to

    Re: Write code to programmatically open Access

    I have admin rights on my machine. Don't understand where it would affect anything???
Page 1 of 2 (19 items) 1 2 Next >
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.