Page 1 of 1

[Solved] How achieve listbox content based on another field

Posted: Wed Jul 11, 2018 4:42 pm
by Maax555
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/3zjli081zslh8 ... 8.odb?dl=0

Re: How to achieve listbox content based on another field

Posted: Thu Jul 12, 2018 3:15 pm
by Maax555
No takers yet:-(

Re: How to achieve listbox content based on another field

Posted: Thu Jul 12, 2018 3:52 pm
by RoryOF
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
viewtopic.php?f=21&t=3519

Re: How to achieve listbox content based on another field

Posted: Thu Jul 12, 2018 5:53 pm
by UnklDonald418
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.

Re: How to achieve listbox content based on another field

Posted: Thu Jul 12, 2018 9:48 pm
by Villeroy
Cascading list boxes with macro code and links to solutions without: viewtopic.php?f=83&t=46470

Re: How to achieve listbox content based on another field

Posted: Wed Jul 18, 2018 4:59 pm
by Maax555
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.

Re: How to achieve listbox content based on another field

Posted: Wed Jul 18, 2018 5:07 pm
by Maax555
Link in original post now corrected.

thanks

Re: How to achieve listbox content based on another field

Posted: Thu Jul 19, 2018 10:41 am
by Maax555
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
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.

Re: How to achieve listbox content based on another field

Posted: Sat Jul 21, 2018 4:39 pm
by UnklDonald418
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

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 

Re: How to achieve listbox content based on another field

Posted: Wed Jul 25, 2018 2:24 pm
by Maax555
Many thanks, looking at this now.

Re: How to achieve listbox content based on another field

Posted: Wed Jul 25, 2018 2:55 pm
by Maax555
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.