Possible to open PDF file locally from Access database?

Answered Possible to open PDF file locally from Access database?

  • 10 April 2012 21:28
     
     

    Not sure exactly how to word this as this is my first time trying to make anything non-web related in VS.  Basically I have my datasource as an Access mdb file and have that displaying fine and is searchable. 

    On one of the fields I need to be able to click on the link/text and have it open a pdf from a subdirectory (\Images\file.pdf).  I have it working fine in the actual access database, but when connecting it through VS the link no longer works.  I tried changing the field to URL and when I click the link nothing happens.  Is there any kind of format or is this even possible this way?

    Basically I am just making an exe that will open the mdb file and let you open an image from one of the fields - have to do it this way so having access or the runtime installed isn't needed.

    Thanks for any help!

Semua Balasan

  • 11 April 2012 0:19
     
      Memiliki Kode

    not sure exactly what do you wanna click on, but if you can perform a click event, then you can use Process.Start() method to start your pdf file.

    System.Diagnostics.Process.Start(@"path and pdfFileName");


    Mitja

  • 11 April 2012 15:14
     
     
    I just want to be able to click on a link in the column of the database/table and have it open a pdf locally in a subdirectory.  I wasn't sure if there was some kind of formatting that needed to be used.  In access you'd just make the field a hyperlink and use #Images\11161.pdf#.
  • 12 April 2012 16:33
     
     

    Here is a little more info, if it helps.  I made the one field DataGridViewLinkColumn - that turns everything into a url, but nothing opens when clicked.

    I just have an access table displayed in the window with data and links.  I'm guessing I need to define how to handle the DataGridViewLinkColumn column?

    My code only seems to consist of the following:

    Public Class Form1

        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            'TODO: This line of code loads data into the 'TestDataSet.Test_Query' table. You can move, or remove it, as needed.
            Me.Test_QueryTableAdapter.Fill(Me.TestDataSet.Test_Query)

        End Sub
    End Class

  • 14 April 2012 0:34
     
     Jawab Memiliki Kode

    Hello, the following will process your DataGridViewLinkColumn.

    private void DataGridView1_CellContentClick(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
    {
    	if (DataGridView1.Columns(e.ColumnIndex) is DataGridViewLinkColumn && ! (e.RowIndex == -1))
    	{
    		Process.Start(DataGridView1.Item(e.ColumnIndex, e.RowIndex).Value.ToString());
    	}
    }


    KSG

  • 16 April 2012 20:43
     
     
    Sorry to sound so newbish, but where would that go?  When adding it in the previous code it just gives a ton of errors.
  • 16 April 2012 23:44
     
     

    Hello Softrac,

    If you look at the signature shown below the event is highlighted which means the code goes into the CellContentClick event. Please refer to the link on CellContentClick for how to use.

    private void DataGridView1_CellContentClick(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)

    Once you have done the above are you still getting IDE errors? If so what exactly are the errors?


    KSG