- Local time
- Today, 07:58
- Joined
- Feb 19, 2002
- Messages
- 43,263
Don't use the multi-select option. Just log one at a time.
Why are you running a query to update the location of the file?
Do I need to set it as FALSE or remove it from the code. If i removed it, would i need to remove or modificate the code reltated to "varItem"??Don't use the multi-select option. Just log one at a time.
I don´t want to add a new row since the row has already been created before. Just want to update the table with the new data using UPDATE command. Which part do i need to remove?It is extremely hard to read code that is not formatted. Please use the code tool when uploading code.
Your logic is garbled. If you are selecting multiple files, you need to use an append query to add a new row for each file. If you only select one at a time, you don't need a query at all. You just put the path into the bound text field of your subform.
Private Sub Command870_Click()
Dim strSql7 As String
Dim f As Object
Dim strFile As String
Dim strFolder As String
Dim varItem As Variant
Set f = Application.FileDialog(3)
'f.AllowMultiSelect = True
If f.Show Then
For Each varItem In f.SelectedItems
strFile = Dir(varItem)
strFolder = Left(varItem, Len(varItem) - Len(strFile))
MsgBox "Folder" & strFolder & vbCLf & _
"File:" & strFile
txtLocation = strFolder + strFile
strSql7 = "UPDATE GC_Eventos SET Cont = " & Me.txtLocation & " WHERE Evento_ID = " & Me.Evento_ID & ""
Debug.Print strSql7
CurrentDb.Execute strSql7
Next
End If
Set f = Nothing
End Sub
Thanks for the like @A380b747 but that doesn't help anyone who finds this thread later. If my solution helped you, please use your words and tell people how you implemented it.
Dim db As Database
Dim rst_PDF As Recordset
Dim rst_Attachment As Recordset
Dim fld_att As Field
Set db = CurrentDb
Set rst_PDF = db.OpenRecordset("Select Contrato FROM GC_Eventos WHERE Evento_ID = Me.Evento_ID")
Set fld_att = rst_PDF("Attachment")
rst_PDF.MoveFirst
Set rst_Attachment = fld_att.Value
rst_PDF.Edit
rst_Attachment.AddNew
rst_Attachment("FileData").LoadFromFile rst_PDF!(Me.txtLocation)
rst_Attachment.Update
rst_PDF.Update
rst_PDF.MoveNext
rst_Facturas.Close
db.Close
Set fld_att = Nothing
Set rst_Attachment = Nothing
Set rst_PDF = Nothing
Set db = Nothing
We've all told you to not store the file inside the database. If you want help, you are at least going to tell us what the error you are getting is.