Adding a New Item to KeyCombo VB Help

The KeyCombo application uses eachcontrol’s ltemData array to store the index of the array element (o r record number, in the case of a random access file) in which the matching record is stored. When a user wants to add a new record, they click the Add New button (see Figure 5.12). When the new record is committed to the database, an OK button appears, and when it’s clicked, the following code goes into action.

After ensuring that the name field is not empty, the program adds the corresponding fields to the three ComboBox controls. The SSN field is inserted in Combol, the VISA # field is in.s.erted in Comboz, and the AMEX # is inserted in Combos. The Arraylndex variable is the index of the element where the new record will be added in the array D~taArray(); it’s the index of the next available element in the array. This number is stored in each ComboBox control’s ItemData array. The New Index property returns the index of the newly added item in a Combo Box control: so the expression ItemData(Combo3. NewIndex) matches the location of the new record in the data array. The fields are stored in the data array. The last few lines cause the keys of the newly added record to appear in the edit box of the ComboBox controls, so that the selected entry matches the fields shown on the right ‘side of the Form.

Selecting an Existing KeyCombo Item When the user selects an item in one of the ComboBox controls, the program retrieves the matching record from the array and displays its fields in the data entry section of the Form. Following is the first ComboBox ccntrol’s Click event handler, which displays the fields that correspond to thekey selected in the Combo Box control.

The Combo1 Control’s Click Event

The event handlers for the other two ComboBox controls are identical. The KeyCombo application is meant to be used for data retrieval only; it’s not a data entry application. The Add New button was included to help you enter some data and test the program, which is why the application lacks a Delete button. The ComboBox controls with the alternative keys doil’t need to be visible at runtime. Depending on the user’s needs, you might want to provide Command buttons that make one of the combo boxes visible. Another improvement would be to replace the TextBox controls with combo boxes so that the user can either .” select an existing item or typ-e-a new one.

Posted on November 5, 2015 in Basic ActiveX Controls

Share the Story

Back to Top
Share This