Populate a ComboBox w/ query results from other ComboBox, DateEdit, Memo, etc

I have a Dialog page with a Memo and two DateEdit boxes. A query is run based on a client # from the memo and a date range from the two DateEdits.
The query works and the report runs OK.
Now, I want to update the page to populate a ComboBox using the results of that query as parameters instead of running the report. The report would then be run based on the selection in the ComboBox.

Can that be done? Which event can I use to execute the query that accepts parameters from the first query?

I attached a screen shot. I would like to run a query using Client # and the two dates. Then the ComboBox at the bottom beside "Select Survey" would be populated with a query based on the previous query.

Both queries work. I just need to know how to populate the ComboBox.
Let me know if I need to clarify.

Thanks

Comments

  • edited June 2014
    I know how to populate ComboBoxes when the DialogPage is first loaded.
    Is there a way to refresh the page after it is loaded and populate the ComboBox at that time?
    Maybe I could call an OnShow event when the second date is entered?
    I don't know. I'll take any suggestions.

    I'm also open to moving the ComboBox to a 2nd DialogPage if that is a better option.
  • edited 2:22PM
    I have tried putting the ComboBox on another DialogPage -DialogPage2. I then show that page on the click event of the OK button on DialogPage1
    The box does populate correctly, but the report crashes when the OK button on DialogPage2 is clicked.
  • edited 2:22PM
    I got it working by putting the ComboBox on a second DialogPage. For some reason, I have to click the OK button twice on the second DialogPage for the report to run. I don't know why it was crashing earlier. It was probably some code I removed.

    Does anyone know why I have to click the OK button twice?

    I would still like to know if there is a way to get it working by just using one DialogPage. I would somehow need to activate the ComboBox or refresh the page after entering the 2 dates and the Client #.

    Please let me know if you have suggestions.
  • edited 2:22PM
    DavidWIII wrote: »
    I have a Dialog page with a Memo and two DateEdit boxes. A query is run based on a client # from the memo and a date range from the two DateEdits.
    The query works and the report runs OK.
    Now, I want to update the page to populate a ComboBox using the results of that query as parameters instead of running the report. The report would then be run based on the selection in the ComboBox.

    Can that be done? Which event can I use to execute the query that accepts parameters from the first query?

    I attached a screen shot. I would like to run a query using Client # and the two dates. Then the ComboBox at the bottom beside "Select Survey" would be populated with a query based on the previous query.

    Both queries work. I just need to know how to populate the ComboBox.
    Let me know if I need to clarify.

    Thanks

    I'll try my original question again.
    Is there a way to refresh a ComboBox after a dialog page loads? Is there an event/action I can call to reload the ComboBox? I want the ComboBox to load from a query that accepts parameters from a memo and two dates selected on the same page. I might call whatever command I need from a button or from an event from another object on the page. It is not enough to have AutoOpenDataSet set to true since the page is already loaded before the parameters are selected. It is also not enough to simply execute the query connected to the ComboBox.
    Please let me know if I need to clarify. Thanks.
  • gordkgordk St.Catherines On. Canada.
    edited 2:22PM
    start by using the onactivate event of the dialogform to do your poulating of objects
    and disable the ok btn you may also want to add a cancel btn
    make sure the creation orfer of the objects follows the correct path.
    look at using the onenter onexit events of each object to acheive what you want
  • edited 2:22PM
    Thanks, gordk
    I do have the OK button disabled.
    I'm still not sure how to load the combobox from whatever event I use.
    I was hoping for a command similar to what's used in .net - DBLookupComboBox.FillData();
    There might not be a command similar to that.
    I did find this code in the demo for loading a CheckListBox:
      BDETable1.Open;
      while not BDETable1.EOF do
      begin
        CheckListBox1.Items.Add(BDETable1.FieldByName('Company').AsString);
        BDETable1.Next;
      end;
    

    .Items and .Add are not properties of a ComboBox.
    Is there anything similar that can be used for a ComboBox?
    I'm also not yet sure how to set the creation order of the objects. I'll see if I can find that.
    I suppose I could try using a CheckListBox instead of the combo.
  • gordkgordk St.Catherines On. Canada.
    edited 2:22PM
    try checklistbox.additem
  • edited 2:22PM
    I can get a checklistbox to load the data.
    Now I have to figure out how to pass that value to another query that creates the report.
    With the ComboBox, I was using KeyField under properties as a parameter in the main query.
    The properties of the query has a param defined as DBLookupComboBox1.keyvalue.
    With the checklistbox, I'll have to define a param for the query with something like CheckListBox.text or CheckListBox.value.
    I haven't found the correct syntax yet

    Thanks for all the suggestions.
  • gordkgordk St.Catherines On. Canada.
    edited July 2014
    paramaterize the query you can point the param to a variable if you need to convert to a set type or directly to a textbox value
    also take a look at the main demo dialogs and script- coosing records to print
  • edited 2:22PM
    Thanks, but I don't yet know how to reference the selection in the CheckListBox. I don't even know how to set a variable or text to the selection. I'm still looking through the manual, demo, and forums.
    Even if I do find it, I'll have to extract the part used as the param. Each row in the CheckListBox will have 3 columns from the table selected in the query.
    One column is a date, another is a name, and the 3rd will be a foreign key used as the param in the data band query. So each row in the CheckListBox will have date + name + foreign key. I will have to extract the foreign key.
    With a DBLookupComboBox, I don't need to include the foreign key in the list. I just set the KeyField to the foreign key and use the KeyValue of the combobox as the param.
    The user only needs to see the date and name.
    I'm not sure if I'm explaining it clearly.
  • edited 2:22PM
    I can get it to work using a DBLookupComboBox if I put it on a second dialogpage. The query used as the data source for the combobox uses the text and date range from the first dialogpage as params. The click event of the OK button on the first dialogpage loads the second dialog page, and the combobox AutoOpenDataSet is set to True.
    The problem I'm having with that approach - the first dialogpage stays open behind the second dialogpage. The OK button on the second page has to be clicked twice. The first click closes the first dialogpage. The second click runs the report. It works, but it doesn't look good having to click the OK button twice.
  • edited 2:22PM
    DavidWIII wrote: »
    I can get it to work using a DBLookupComboBox if I put it on a second dialogpage. The query used as the data source for the combobox uses the text and date range from the first dialogpage as params. The click event of the OK button on the first dialogpage loads the second dialog page, and the combobox AutoOpenDataSet is set to True.
    The problem I'm having with that approach - the first dialogpage stays open behind the second dialogpage. The OK button on the second page has to be clicked twice. The first click closes the first dialogpage. The second click runs the report. It works, but it doesn't look good having to click the OK button twice.

    I solved the above problem. In the click event of DialogPage1 I had coded:
    DialogPage2.ShowModal;

    I thought I needed that to call DialogPage2. It is unnecessary and was causing DialogPage1 to stay open in the background.

    I can use the report that way but would still like to know how to load a DBLookupComboBox after the DialogPage has already loaded.

    Thanks for the suggestions.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.