Search code examples
vbams-access

MS Access - Saving link to another table with msoFileDialogFolderPicker , other then "me"


I'm trying to save a link location using msoFileDialogFolderPicker. I want to save the link inside another table with the name of "Characterization results" to field named "PL Reports".

How i can refer to a field in another table like: PL Reports_Characterization results ?

Thanks

Private Sub Load_HyperlinkBTN_Click()

   Const msoFileDialogFolderPicker As Long = 4

   Dim fd As Object
'Create a FileDialog object as a File Picker dialog box.
   Set fd = Application.FileDialog(msoFileDialogFolderPicker)
'Use a With...End With block to reference the FileDialog object.
   With fd
'Set the initial path to the D:\Documents\ folder.
  ' InitialFileName = "\\ap1\tools\db\"
   .Title = "Select Attachment"
'Use the Show method to display the File Picker dialog box and return the user's action.
'If the user presses the action button...
   If .Show = -1 Then
'   DoCmd.GoToRecord , "", acNewRec
    Me![Charactisation results_PL Reports] = "#" & .SelectedItems(1) & "#"

'  **

'If the user presses Cancel...
   Else
   End If
 End With

'Set the object variable to Nothing.
   Set fd = Nothing

End Sub

Solution

  • This should insert a new record in table Characterization results and save the value .SelectedItems(1) in the field PL Reports:

    CurrentDb.Execute "INSERT INTO [Characterization results] ([PL Reports]) VALUES ('" & .SelectedItems(1) & "');", dbFailOnError

    P.S. You should really avoid using space in names as @June7 stated.