[Solved] Form always opens first record

Creating and using forms

[Solved] Form always opens first record

Postby jklane » Fri Dec 11, 2015 5:18 am

Hi, I'm working on my first OO database and hoping someone can help me. Since I'm a novice at this, I'm hoping it's something simple I've overlooked or don't understand. Any help would be greatly appreciated.

I have two tables, Customers and Vehicles. The Customers table has a primary key, CustomerID. The Vehicles table has a primary key, ID. One customer can have more than one vehicle. I have created a form where I can select a customer, which then displays the vehicles belonging to that customer. I select a vehicle and click a Push Button to run a macro that opens a new form with customer and vehicle details.

Here's the macro:

Code: Select all   Expand viewCollapse view
Sub OpenFormMaintDetail
const sNewDocumentName="MaintDetail"
Doc = StarDesktop.CurrentComponent
Form = Doc.DrawPage.Forms.GetByIndex(0)
CustID = Form.getByName("TxtCustID").Text
frm_container = ThisDatabaseDocument.FormDocuments.getByName(sNewDocumentName)
frm_container.open
FormModel2 = frm_container.component.DrawPage.forms.getbyindex(0)
FormModel2.Filter =("Customers.CustomerID = " & CustID)
FormModel2.ApplyFilter = True
FormModel2.reload()
end sub

The problem is that regardless of what vehicle I select, the new form always displays the first vehicle in the table for that customer. To be clear, the original form contains a mainform (customer info) and a subform (vehicle info). I'm wondering if I need to filter by vehicle id (ID), but nothing I've tried has worked so far and I've been unsuccessful researching this forum and the net for a solution.
Last edited by Hagar Delest on Fri Feb 26, 2016 10:49 pm, edited 1 time in total.
Reason: tagged [Solved].
OpenOffice 4.1.2 on Windows 10
jklane
 
Posts: 3
Joined: Fri Dec 11, 2015 12:06 am

Re: Form always opens first record

Postby F3K Total » Sat Dec 12, 2015 8:36 am

Hi,
the code seems to be correct. If you load up that .odb-file, only containing a few records having fake-data, we can help you.
If the file should be to big for upload, first execute once via Tools/SQL...
Code: Select all   Expand viewCollapse view
CHECKPOINT DEFRAG
to compress the database.
R
    MMove 1.0.6
  • Extension for easy, exact positioning of shapes, pictures, controls, frames ...
    my current system
  • Windows 7 OOo, AOO, LOLinux Mint OOo, AOO, LO
F3K Total
Volunteer
 
Posts: 914
Joined: Fri Dec 16, 2011 8:20 pm

Re: Form always opens first record

Postby jklane » Sun Dec 13, 2015 1:02 am

R,
Thank you for the reply. I've changed the names to the US presidential candidates' names. Donald Trump and Hillary Clinton have 2 vehicles each. Everyone else has one vehicle. If you open the form "Maintenance" and select a record then click PRINT REPORT, you'll see that the first vehicle assigned to a customer is opened.
Attachments
Vehicle Maintenance System.odb
(43.3 KiB) Downloaded 72 times
OpenOffice 4.1.2 on Windows 10
jklane
 
Posts: 3
Joined: Fri Dec 11, 2015 12:06 am

Re: Form always opens first record

Postby F3K Total » Sun Dec 13, 2015 1:58 am

Hi,
this should work:
Code: Select all   Expand viewCollapse view
Sub OpenFormMaintDetail
    Doc = StarDesktop.CurrentComponent
    Form = Doc.DrawPage.Forms.GetByName("MainForm")
    CustID = Form.columns.getbyname("CustomerID").getint
    SubForm = Form.getbyname("SubForm")
    VehikelID = Subform.Columns.getbyname("ID").getint
    frm_container = ThisDatabaseDocument.FormDocuments.getByName("MaintDetail")
    frm_container.open
    MainFormMaintDetail = frm_container.component.DrawPage.forms.getbyName("MainForm")
    MainFormMaintDetail.Filter =("CustomerID = " & CustID)
    MainFormMaintDetail.ApplyFilter = True
    MainFormMaintDetail.reload()
    SubFormMaintDetail = MainFormMaintDetail.getbyname("SubForm")
    SubFormMaintDetail.Filter =("ID = " & VehikelID)
    SubFormMaintDetail.ApplyFilter = True
    SubFormMaintDetail.reload()
end sub
I suggest you, to inspect your forms by using the Form Navigator, then you'll understand what MainForm, SubForm ... are. They are the names of the structural forms.

R
Attachments
Vehicle Maintenance System.odb
(42.99 KiB) Downloaded 84 times
    MMove 1.0.6
  • Extension for easy, exact positioning of shapes, pictures, controls, frames ...
    my current system
  • Windows 7 OOo, AOO, LOLinux Mint OOo, AOO, LO
F3K Total
Volunteer
 
Posts: 914
Joined: Fri Dec 16, 2011 8:20 pm

Re: Form always opens first record

Postby jklane » Sun Dec 13, 2015 2:15 am

Yes! That worked! Thank you!
OpenOffice 4.1.2 on Windows 10
jklane
 
Posts: 3
Joined: Fri Dec 11, 2015 12:06 am


Return to Forms

Who is online

Users browsing this forum: No registered users and 1 guest