File Selection control on Base Forms

Discuss the database features
Post Reply
boatfreq
Posts: 3
Joined: Mon Jun 02, 2008 10:07 pm

File Selection control on Base Forms

Post by boatfreq »

I would like to store file names rather than images in my database, and would like to use the "File Selection" feature found under "more controls" on my form to load the data. Is there a way to link this data entry feature to a database field? If not, any suggestions on providing a point-and-click data entry feature for image file names?
QuazzieEvil
Volunteer
Posts: 283
Joined: Tue Dec 04, 2007 6:38 pm
Location: Houston, TX

Re: File Selection control on Base Forms

Post by QuazzieEvil »

this control is not data-aware (you cannot bind it to a table column). you can provide an event handler for the Text Modified event of this control (file control) to update the desired column based on the url selected.
boatfreq
Posts: 3
Joined: Mon Jun 02, 2008 10:07 pm

Re: File Selection control on Base Forms

Post by boatfreq »

Thanks -- I'm sure this will work if I can figure out the simple macro code, but I am not a coder. Here are the details:

I have a product catalog database ("Catalog") and a form ("Products") to enter data. The "File Selection" control updates a form text field ("FileSelection"), and have set the text modified event to execute a macro called ChangeFName.

Now I need a simple macro to update the "ImageFName" field in the Catalog database field to equal "FileSelection". I tried the following code (keep in mind I don't know what I am doing, and may be totally off base!).

Sub ChangeFName
Dim TopForm As Object
TopForm = ThisComponent.DrawPage.Forms.GetByName("MainForm")
TopForm.GetByName("ImageFName") = TopForm.GetByName("FileSelection")
End sub

XRay tells me that "MainForm" is the correct form name, but I cannot find any of my data elements using GetByName. Of course XRay confirms this error. I cannot find any of my data elements in XRay.
QuazzieEvil
Volunteer
Posts: 283
Joined: Tue Dec 04, 2007 6:38 pm
Location: Houston, TX

Re: File Selection control on Base Forms

Post by QuazzieEvil »

A couple of things:

your event handler/subroutine must take a parameter to hold the event information. Second, you need to update the text property of one control with the text property of the other. but, if ImageFName is bound to a table column, you must update the column to which that control is bound, or the text property of that control's view. (its a bit confusing I know)

you can get the form as you have it, or via the event object. I am assuming that you have one form in this form document. or at least the controls you are using here are all located in the form 'MianForm'

Code: Select all

Sub ChangeFName(Event As Object)
    Dim Form As Object
    Dim FilePath As String

    Form=ThisComponent.DrawPage.Forms.GetByName("MainForm") 
    FilePath=TopForm.GetByName("FileSelection").Text
    REM NOW, you must access the column  to which the control 'ImageFName' is bound. 
   REM Let's assume this control is bound to a column with the same name.
   Form.Columns.getByName("ImageFName").updateString(FilePath)
   REM This is one solution.
   REM form controls have a model and a view, you can also update the data via the control view, but this method works as well--via the bound column  
End Sub
I have not tested this, let me know if it gives you errors.
boatfreq
Posts: 3
Joined: Mon Jun 02, 2008 10:07 pm

Re: File Selection control on Base Forms

Post by boatfreq »

Issue solved! Thanks for your help.
thebuc1010
Posts: 1
Joined: Thu Jun 23, 2011 7:35 pm

Re: File Selection control on Base Forms

Post by thebuc1010 »

Hey guys.. so this is exactly what I would like to implement in my form.
But I'm having no luck with the provided macro. Simply nothing happens. I figure I'm doing it wrong.

I have no experience using macros in the past.
Can anyone explain to me how to do this step by step?
:( i don't even know how to explain what i've tried i feel so noob.
Openoffice 3.2 on Ubuntu 10.04
Post Reply