| View previous topic :: View next topic |
| Author |
Message |
Toula Newbie

Joined: 29 Dec 2010 Posts: 2
|
Posted: Wed Dec 29, 2010 12:28 pm Post subject: adding an attachment in a table - I need a GENIUS to help me |
|
|
I'm trying to create a database that has an attachment in it. I'm trying to attach pdf files from my computer on the database.
I really hope this makes sense.
For example:
After creating a table in design view:
I can put in
Name
Address
Phone
I'm trying to figure out if I can do attachment
Name
Address
Phone
Attachment
... and have it work... so when I look at the table I can click on it (after the databse is finished) and find the attachement associated with that entry.
I know I can do that in access
... wow I hope that makes sense |
|
| Back to top |
|
 |
QuazzieEvil Super User

Joined: 17 Jan 2007 Posts: 599 Location: Houston, TX
|
Posted: Wed Dec 29, 2010 7:58 pm Post subject: |
|
|
It is possible to store files in the database itself, but not advisable (specially a Base native database).
This is an example of now to add a file (assuming the column named FILE, is of type binary
| Code: |
Sub addFile2(Event As Object)
Dim FilePicker As Object, SFA As Object
Dim FileURL As String
Dim Form As Object
Dim IStream As Object
Form=Event.Source.Model.Parent
REM file dialog
FilePicker = CreateUnoService( "com.sun.star.ui.dialogs.FilePicker" )
SFA = CreateUnoService( "com.sun.star.ucb.SimpleFileAccess" )
REM execute file dialog
If FilePicker.execute() Then
FileURL = FilePicker.Files(0)
InputStream=SFA.openFileRead( FileURL)
Form.Columns.getByName("FILEURL").updateString(FileURL)
Form.Columns.getByName("FILE").updateBinaryStream(InputStream,InputStream.Length)
InputStream.closeInput()
End If
End Sub
|
of Course, you may want to get it out of the column and open it at some point
| Code: |
Sub cmdViewContent_OnClick(Event As Object)
Dim Form As Object
Dim ContentCol As Object
Dim SFA As Object
Dim FileURL As String
Dim FileName As String
Dim OpenWith As String
Dim tmpArr() As String
Form=Event.Source.Model.Parent
OpenWith=Form.getByName("txtOPENWITH").Text
If OpenWith="" Then
MsgBox "Error. Please select a program with which to open this file"
Exit Sub
End If
ContentCol=Form.Columns.getByName("FILE")
SFA = CreateUnoService( "com.sun.star.ucb.SimpleFileAccess" )
REM CREATE TMP FILE
tmpArr=Split( Form.getByName("txtFILEURL").Text,"/" )
FileName= Year(Now) & Month(Now) & Day(Now) & Hour(Now) & Minute(Now)_
& "_" & tmpArr( UBound(tmpArr) )
FileURL=Environ("TMP") & "\" & FileName REM STORE IN TMP DIR
SFA.writeFile(ConvertToURL(FileURL),ContentCol.BinaryStream)
Shell(OpenWith & " " & FileURL)
End Sub
|
OpenWith contains the path to the program that can open the file--can handle differently to suite your needs.
Also, the approach for creating the temp file is just one approach.
A better approach is to store the URL in the database, and keep all files in the file system. To open the file, follow same steps as above for opening the temp file.
_________________ Free Docs @ http://www.baseprogramming.com/resources.html
Book @ lulu.com http://www.lulu.com/content/2455551 |
|
| Back to top |
|
 |
Toula Newbie

Joined: 29 Dec 2010 Posts: 2
|
Posted: Thu Dec 30, 2010 5:56 am Post subject: Thank you! |
|
|
Thank you for that! Makes more sense now.
Perfect  |
|
| Back to top |
|
 |
mastannous Newbie

Joined: 15 Feb 2012 Posts: 1
|
Posted: Wed Feb 15, 2012 8:39 pm Post subject: HELP!!!!!!!!!!! |
|
|
i am trying to use this code please can someone explain what does FILEURL and txtFILEURL stand for?
and i dont know how to use the second code (Sub cmdViewContent_OnClick(Event As Object) like to which macro.
Thanks!! |
|
| Back to top |
|
 |
|