Consulting

Results 1 to 5 of 5

Thread: Excel to Access Attachment

  1. #1

    Excel to Access Attachment

    I am trying to send an attachment to Access through Excel VBA. Is there any way I can do that. DO anyone know how to do it.

  2. #2
    VBAX Contributor
    Joined
    Jun 2014
    Posts
    107
    Location
    Quote Originally Posted by patilbush View Post
    I am trying to send an attachment to Access through Excel VBA. Is there any way I can do that. DO anyone know how to do it.
    What you mean by attachment? Can you be more specific on what you are trying to do?

  3. #3
    Thank you for the reply
    Actually I am trying to save file into access database into Attachment field using excel VBA. I want to create a button in Excel VBA and when you click the button brower should open and select a file then after selecting the file should get saved in Access as an attachment.

    Here is my code to op file using file dialog box

    Private Sub CommandButton1_Click()
    Dim cnn As ADODB.Connection
    Set cnn = New ADODB.Connection
    Dim fd As FileDialog
    Dim var As Boolean
    Set fd = Application.FileDialog(msoFileDialogOpen)
    fd.Filters.Clear
    fd.Filters.Add "All Files", "*.*"
    fd.FilterIndex = 1
    var = fd.Show
    If Not var Then
    MsgBox "Please Select a file"
    Exit Sub
    End If
    fd.Execute
    Unload Me
    End Sub


    Here is my code to save file using file dialog box

    Dim cnn As ADODB.Connection
    Set cnn = New ADODB.Connection
    Dim fd As FileDialog
    Dim var As Boolean
    Set cnn = New ADODB.Connection
    cnn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ThisWorkbook.Path & "\File.accdb;Persist Security Info=False;"
    Set fd = Application.FileDialog(msoFileDialogSaveAs)
    var = fd.Show
    If Not var Then
    MsgBox "Enter name to save file"
    End If
    fd.Execute

    But this code is saving my file to selected destination but I want it should save directly into access database in Attachment field.

    Thank you

  4. #4
    VBAX Contributor
    Joined
    Jun 2014
    Posts
    107
    Location
    Quote Originally Posted by patilbush View Post
    Thank you for the reply
    Actually I am trying to save file into access database into Attachment field using excel VBA. I want to create a button in Excel VBA and when you click the button brower should open and select a file then after selecting the file should get saved in Access as an attachment.

    Here is my code to op file using file dialog box

    Private Sub CommandButton1_Click()
    Dim cnn As ADODB.Connection
    Set cnn = New ADODB.Connection
    Dim fd As FileDialog
    Dim var As Boolean
    Set fd = Application.FileDialog(msoFileDialogOpen)
    fd.Filters.Clear
    fd.Filters.Add "All Files", "*.*"
    fd.FilterIndex = 1
    var = fd.Show
    If Not var Then
    MsgBox "Please Select a file"
    Exit Sub
    End If
    fd.Execute
    Unload Me
    End Sub


    Here is my code to save file using file dialog box

    Dim cnn As ADODB.Connection
    Set cnn = New ADODB.Connection
    Dim fd As FileDialog
    Dim var As Boolean
    Set cnn = New ADODB.Connection
    cnn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ThisWorkbook.Path & "\File.accdb;Persist Security Info=False;"
    Set fd = Application.FileDialog(msoFileDialogSaveAs)
    var = fd.Show
    If Not var Then
    MsgBox "Enter name to save file"
    End If
    fd.Execute

    But this code is saving my file to selected destination but I want it should save directly into access database in Attachment field.

    Thank you
    Hopefully this answers your question but the Access doesn't store an attachment but stores the name and locations of the attachment. You would have to use code to either move the attachment were you want it and set the path or use VBA to create a "link" to the attachment to store in the table. You could also use a hyperlink to have Access open it - which might be easier.

  5. #5
    Thank you so much
    Can you help me with the code to save the path of selected file to store into access.

Tags for this Thread

Posting Permissions

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