Update Table with Button from Dialog Box

Discuss the database features
Post Reply
jsvanc
Posts: 10
Joined: Fri Feb 16, 2018 4:11 am

Update Table with Button from Dialog Box

Post by jsvanc »

I have a form that opens a dialog box with a list box in it.

I have this code to populate the list box from information on the parent form:

Code: Select all

Sub PopulatedlgRemoveJobContactListBox()

DataSource = ThisComponent.Parent.DataSource.GetConnection("","")

JobID = ThisComponent.DrawPage.Forms.GetByName("MainForm").GetByName("txtJobID").text
SQLResult=createUnoService("com.sun.star.sdb.RowSet")

SQLQuery = "Select ""JobContacts"".*, ""Contacts"".""ContactName"" AS cntName FROM ""JobContacts"", ""Contacts"" WHERE ""JobID"" = " & JobID & " AND ""Contacts"".""ContactID"" = ""JobContacts"".""ContactID"""
SQLResult.activeConnection = DataSource
SQLResult.Command = SQLQuery
SQLResult.execute

exitOK=com.sun.star.ui.dialogs.ExecutableDialogResults.OK
DialogLibraries.LoadLibrary("Standard")

Dialog=CreateUnoDialog(DialogLibraries.Standard.dlgRemoveJobContact)
DialogField=Dialog.GetControl("lstContacts")

While SQLResult.next
ListBoxItem = SQLResult.getString(4)
DialogField.additem(ListBoxItem, DialogField.ItemCount)
Wend
If Dialog.Execute=exitOK Then
CurrentItemName=Dialog.SelectedItem
End If

End Sub
So now what I need to do is when I click the Remove Contact button, it will delete a row on my table where JobID = "something" and ContactID = "Information from listbox"
I'm tried to do another sub

Code: Select all

Sub RemoveContact()
DataSource = ThisComponent.Parent.DataSource.GetConnection("","")
SQLDelete = "DELETE FROM ""JobContacts"" WHERE ""JobID"" = " & JobID & " AND ""ContactID"" = " & Dialog.SelectedItem(3)
SQLResult.activeConnection = DataSource
SQLResult.Command = SQLDelete
SQLResult.execute
exitOK=com.sun.star.ui.dialogs.ExecutableDialogResults.OK
End Sub
But I'm not sure how to call the information in the list box to make the ContactID = "SelectedItem"
I've added an attachment of the Dialog box, not that it will help, but just in case.

I am new to Base and Macros. Any help is appreciated. Thank you.
Attachments
2018-02-22.png
2018-02-22.png (3.33 KiB) Viewed 1766 times
OpenOffice 4.1.5 on Windows 10
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Update Table with Button from Dialog Box

Post by Villeroy »

It is almost trivial to add a "power filtering list box" to your form (or even easier: use the built-in form filter) in order to display what you are going to delete and then push a delete button.
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
jsvanc
Posts: 10
Joined: Fri Feb 16, 2018 4:11 am

Re: Update Table with Button from Dialog Box

Post by jsvanc »

I'll check on the power filtering and built-in form filter. Thank you Villeroy.
OpenOffice 4.1.5 on Windows 10
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Update Table with Button from Dialog Box

Post by Villeroy »

You find many examples in the forum for Base tutorials.
One that demonstrates power filtering and how Base works together with Calc: viewtopic.php?t=88516&p=416210#p416210
It has a one-line macro but can be set up without any macro which requires 3 more clicks per sheet update.
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
Post Reply