OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

adding an attachment in a table - I need a GENIUS to help me

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Base
View previous topic :: View next topic  
Author Message
Toula
Newbie
Newbie


Joined: 29 Dec 2010
Posts: 2

PostPosted: Wed Dec 29, 2010 12:28 pm    Post subject: adding an attachment in a table - I need a GENIUS to help me Reply with quote

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
View user's profile Send private message
QuazzieEvil
Super User
Super User


Joined: 17 Jan 2007
Posts: 599
Location: Houston, TX

PostPosted: Wed Dec 29, 2010 7:58 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Toula
Newbie
Newbie


Joined: 29 Dec 2010
Posts: 2

PostPosted: Thu Dec 30, 2010 5:56 am    Post subject: Thank you! Reply with quote

Thank you for that! Makes more sense now.

Perfect Smile
Back to top
View user's profile Send private message
mastannous
Newbie
Newbie


Joined: 15 Feb 2012
Posts: 1

PostPosted: Wed Feb 15, 2012 8:39 pm    Post subject: HELP!!!!!!!!!!! Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Base All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group