[Solved] How achieve listbox content based on another field

Creating and using forms

[Solved] How achieve listbox content based on another field

Postby Maax555 » Wed Jul 11, 2018 4:42 pm

Ok, i have not posted on here for a while as i have tried to get this working myself without success.
I have supplied a link to my database in the hope someone can download and take a look as I just cant get it to work.
Any similar examples i can find just cant be adapted (by me) for my needs.
So in the Form PartNumber2 I have everything working ok apart from SimilarPart listbox and ReplacesPart listbox.

The idea is that after the customer has been chosen from the list box the red listboxes will be populated with a list of all PartNumbers related to the CustomerID. The two listboxes will have the same list in them to choose from. When the desired SimilarPart and ReplacesPart have been chosen the record can be saved and the details will update to the PartNumber2 table. I have supplied a Dropbox link for those who care (or should i say dare) to take a look.

I would very much appreciate someone taking a look as I have spent a serious amount of hours try to work this out.
many thanks.
If there is a better way to share the database please let me know.

Link corrected.
https://www.dropbox.com/s/3zjli081zslh8bk/Project%20Tracking18072018.odb?dl=0
Last edited by Maax555 on Wed Jul 25, 2018 2:57 pm, edited 2 times in total.
Regards Maax
LibreOffice 5.4 on Windows 7
Maax555
 
Posts: 106
Joined: Tue Mar 28, 2017 11:56 am

Re: How to achieve listbox content based on another field

Postby Maax555 » Thu Jul 12, 2018 3:15 pm

No takers yet:-(
Regards Maax
LibreOffice 5.4 on Windows 7
Maax555
 
Posts: 106
Joined: Tue Mar 28, 2017 11:56 am

Re: How to achieve listbox content based on another field

Postby RoryOF » Thu Jul 12, 2018 3:52 pm

If you have a subroutine to populate a listbox dynamically, it should be simple to pass the selection parameter from the first listbox to that subroutine to control its population.

The code snippet in this thread might be helpful
https://forum.openoffice.org/en/forum/viewtopic.php?f=21&t=3519
Apache OpenOffice 4.1.5 on Xubuntu 18.04 (mostly 64 bit version) and infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 27365
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: How to achieve listbox content based on another field

Postby UnklDonald418 » Thu Jul 12, 2018 5:53 pm

I went to the link you provided and downloaded Project Tracking Test V1.17-RFQ.odb
So in the Form PartNumber2 I have everything working ok apart from SimilarPart listbox and ReplacesPart listbox.

I see no Form PartNumber2
When the desired SimilarPart and ReplacesPart have been chosen the record can be saved and the details will update to the PartNumber2 table.

Likewise, I find no PartNumber2 table.
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.5 & LibreOffice 6.1.1.2 - Windows 10 Professional
UnklDonald418
Volunteer
 
Posts: 966
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: How to achieve listbox content based on another field

Postby Villeroy » Thu Jul 12, 2018 9:48 pm

Cascading list boxes with macro code and links to solutions without: https://forum.openoffice.org/en/forum/v ... 83&t=46470
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, OpenOffice 4.x & LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 25767
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: How to achieve listbox content based on another field

Postby Maax555 » Wed Jul 18, 2018 4:59 pm

oh, really sorry. I will check to see if i have incorrectly uploaded a different version. Really sorry but do very much appreciate taking time to look. Let me come back. Also apologies for delay as I have had a few days holiday.

thanks again.
Regards Maax
LibreOffice 5.4 on Windows 7
Maax555
 
Posts: 106
Joined: Tue Mar 28, 2017 11:56 am

Re: How to achieve listbox content based on another field

Postby Maax555 » Wed Jul 18, 2018 5:07 pm

Link in original post now corrected.

thanks
Last edited by Maax555 on Fri Jul 20, 2018 9:48 am, edited 1 time in total.
Regards Maax
LibreOffice 5.4 on Windows 7
Maax555
 
Posts: 106
Joined: Tue Mar 28, 2017 11:56 am

Re: How to achieve listbox content based on another field

Postby Maax555 » Thu Jul 19, 2018 10:41 am

RoryOF wrote:If you have a subroutine to populate a listbox dynamically, it should be simple to pass the selection parameter from the first listbox to that subroutine to control its population.

The code snippet in this thread might be helpful
https://forum.openoffice.org/en/forum/viewtopic.php?f=21&t=3519


I have looked at this and in all honesty dont fully comprehend it.
My thoughts were that this macros would perhaps create a pop up with the wordlist words to choose from using LO Writer.
I created a new database with a wordlist table, created a form with a listbox and also inserted the macro into a push button.
The result was a failed to connect error.
As there is no example database to download with the above macro in I was a little lost.
Regards Maax
LibreOffice 5.4 on Windows 7
Maax555
 
Posts: 106
Joined: Tue Mar 28, 2017 11:56 am

Re: How to achieve listbox content based on another field

Postby UnklDonald418 » Sat Jul 21, 2018 4:39 pm

This should get you started.
Use the Mouse button pressed event of the ListBox control(s).
Since the macro uses the event to identify the which control called it, it should work for both Similar Part and Replaces Part.
Code: Select all   Expand viewCollapse view
Sub setListBoxListSource(oEvent As Object)
   Dim oForm As Object
   Dim oModel As Object
   Dim strSQL As String
   Dim SelectedPos As Integer
   Dim SelectedItem As String
   Dim CID as integer
'If Not Globalscope.BasicLibraries.isLibraryLoaded("MRILib") Then
'      Globalscope.BasicLibraries.LoadLibrary( "MRILib" )
'End If
'Dim oMRI as object
'oMRI = CreateUnoService( "mytools.Mri" )
   
    oModel = oEvent.Source.Model
    oForm = oModel.Parent
    CID = oForm.getByName("fmtCustomerID").CurrentValue
    strSQL="SELECT ""PartNumber"", ""PartNumberID"" FROM ""PartNumber2"" WHERE ""CustomerID"" = " & CID
    oModel.ListSourceType = com.sun.star.form.ListSourceType.SQL
    oModel.ListSource=Array(strSQL)
    oModel.refresh()
'oMRI.inspect oModel
End Sub
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.5 & LibreOffice 6.1.1.2 - Windows 10 Professional
UnklDonald418
Volunteer
 
Posts: 966
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: How to achieve listbox content based on another field

Postby Maax555 » Wed Jul 25, 2018 2:24 pm

Many thanks, looking at this now.
Regards Maax
LibreOffice 5.4 on Windows 7
Maax555
 
Posts: 106
Joined: Tue Mar 28, 2017 11:56 am

Re: How to achieve listbox content based on another field

Postby Maax555 » Wed Jul 25, 2018 2:55 pm

Brilliant. Works perfectly. Cant thank you (and all the other that have supported me) enough as I now feel I am not far off actually being able to use this database or at least moving on to creating some reports. I still have a lot to do but this was a big sticking point for me, so once again a big thank you.
Regards Maax
LibreOffice 5.4 on Windows 7
Maax555
 
Posts: 106
Joined: Tue Mar 28, 2017 11:56 am


Return to Forms

Who is online

Users browsing this forum: No registered users and 3 guests