[Solved] Activate and deactivate a List Box

Discuss the database features
Post Reply
pinco pallo
Posts: 89
Joined: Tue Jul 16, 2013 2:24 pm

[Solved] Activate and deactivate a List Box

Post by pinco pallo »

Hello,
in my database I have a macro that runs by a check box that activates or deactivates a List Box manually.
I would like the List Box to be activated automatically when the content of the field Table = "D", that is only when I select "TabD" in the Group Box.
When the Table field is different from "D", the List Box must be disabled.
How do I change the macro?
Thanks.
Attachments
Condominium Fees.odb
(14.72 KiB) Downloaded 152 times
Last edited by pinco pallo on Fri Oct 27, 2017 7:36 am, edited 1 time in total.
LiBO 6.2.8.2 on macOS 10.12.6 (Sierra)
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Activate and deactivate a List Box

Post by Villeroy »

Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
pinco pallo
Posts: 89
Joined: Tue Jul 16, 2013 2:24 pm

Re: Activate and deactivate a List Box

Post by pinco pallo »

Thank you, but i am only looking for help to modify this code to work with a text box instead with a ceck box.

Code: Select all

REM  *****  BASIC  *****

    Sub c_box_on_off(oEv) 
    Dim otipo as Integer
    otipo = oEv.Source.State
    If otipo = 1 Then  
    oModel = oEv.Source.Model
    oModel.parent.getbyname("List Box 1").enabled=true  
    oModel.parent.reload()
    End If
    If otipo = 0 Then  
    oModel = oEv.Source.Model
    oModel.parent.getbyname("List Box 1").enabled=false  
    oModel.parent.reload()
    End If
  End sub
LiBO 6.2.8.2 on macOS 10.12.6 (Sierra)
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Activate and deactivate a List Box

Post by RoryOF »

Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
pinco pallo
Posts: 89
Joined: Tue Jul 16, 2013 2:24 pm

Re: Activate and deactivate a List Box

Post by pinco pallo »

Yes, but that macro is different from that posted here.
LiBO 6.2.8.2 on macOS 10.12.6 (Sierra)
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Activate and deactivate a List Box

Post by RoryOF »

Can you write a short macro to examine the field table for "D" and print a message to say if it is D or not D? If so, then you can simply modify either of your macros to enable or disable the list box on the D condition. Such conditional programming is elementary flow control.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Activate and deactivate a List Box

Post by Villeroy »

What an incomprehensible, complicated mess with two tables!
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
pinco pallo
Posts: 89
Joined: Tue Jul 16, 2013 2:24 pm

Re: Activate and deactivate a List Box

Post by pinco pallo »

I apologize if I did not explain it.
The main table is Condominium_fees. In the Form with the same name, I use a List Box with the names of the secondary table Condominium_records to enter the Name field.
I look for a way to enter the Name only if the Table field contains the value "D" without using the ceck box that works with the macro.
Can you change the macro? do you need a new one?
Thanks for your patience.
Attachments
Condominium Fees_2.odb
(14.24 KiB) Downloaded 137 times
Schermata 10-2458053 alle 12.09.20.png
Schermata 10-2458053 alle 12.09.36.png
LiBO 6.2.8.2 on macOS 10.12.6 (Sierra)
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Activate and deactivate a List Box

Post by Villeroy »

It's perfectly clear that your database is not properly normalized and that you are not able to overcome this design flaw by means of Basic macros.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
pinco pallo
Posts: 89
Joined: Tue Jul 16, 2013 2:24 pm

Re: Activate and deactivate a List Box

Post by pinco pallo »

I do not know what is not normalized on my database. There are 2 related tables and a form that compiles a field of a table with the contents of the field of another table. To do so, it uses a List Box.
LiBO 6.2.8.2 on macOS 10.12.6 (Sierra)
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Activate and deactivate a List Box

Post by Villeroy »

What does A, B and C stand for?
What does the Amount column actually amount?
What are TabA, TabB and TabC within the cross table amount?
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
pinco pallo
Posts: 89
Joined: Tue Jul 16, 2013 2:24 pm

Re: Activate and deactivate a List Box

Post by pinco pallo »

It is a simplified database, those fields are used for other processing.
I need to, if the field Table <> "D" , I can not enter the Name field (therefore List Box deactivate). To avoid mistakes.
LiBO 6.2.8.2 on macOS 10.12.6 (Sierra)
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Activate and deactivate a List Box

Post by Villeroy »

Find the right event for the text box and do the right thing if oEv.Source.Text = "D" and the right elseif.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
UnklDonald418
Volunteer
Posts: 1544
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Activate and deactivate a List Box

Post by UnklDonald418 »

I've been messing with this and here is what I did to make it work for me.
The original macro has been modified

Code: Select all

REM  *****  BASIC  *****


Sub c_box_on_off(oEv) '
    Dim otipo as BOOLEAN
    Dim ACName as STRING
    
    ACName = oEv.Source.AccessibleContext.AccessibleName
    If ACName = "TabD" Then
        otipo = oEv.Source.State
		If otipo Then
			oEv.Source.Model.parent.getbyname("List Box 1").enabled=True  
		End IF
	Else
			oEv.Source.Model.parent.getbyname("List Box 1").enabled=False  
	End If
End sub
I attached this macro to the Mouse button released Event on each of the 4 Option buttons.
But I found that when the next record was displayed state of the "List Box 1" might not reflect what was now displayed. There was a problem also if the first record had D in the Table field.
Addressing these issues required a second macro

Code: Select all

REM  *****  BASIC  *****

Sub c_box_on_off2(oEv) 

    Dim TblName as STRING

    TblName = oEv.Source.getByName("txtTable").Text
    If TblName = "D" Then
          oEv.Source.getbyname("List Box 1").enabled=True
    Else
          oEv.Source.getbyname("List Box 1").enabled=False
    End If
End sub
This macro is attached to the After record change Event and also the When Loading Event of MainForm.
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.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
pinco pallo
Posts: 89
Joined: Tue Jul 16, 2013 2:24 pm

Re: Activate and deactivate a List Box

Post by pinco pallo »

Hi @UnklDonald418, it works perfectly, I do not know how to thank you! :super: :bravo:
Attachments
Condominium Fees_3.odb
(14.67 KiB) Downloaded 164 times
LiBO 6.2.8.2 on macOS 10.12.6 (Sierra)
Post Reply