Solved

Adding records to a Flexgrid from a Combo Box

Posted on 2002-06-17
3
283 Views
Last Modified: 2006-11-17
I am using VB 6.0 with WIN 2000 operating system.  I want to populate a small flexgrid consisting of only two columns of data from a combo box having only two columns. When the user clicks on the command button event, the textbox fields of Column 1 and Column 2 of the combo box  must be added to the flexgrid.  When a second selection value is placed in the textbox of the combo box and the user presses the command button, Column 1 and Column 2  data of the combo box should be added to the flexgrid.  The user should now see the following data in the flexgrid:

      Facility                   Description  
          1                        Warehouse
          2                       Administration


If the user continues to list new data in the combo box and press the command button to add the data to the flexgrid, the system should add the next facility number and description to the flexgrid.  The user should then have the following result in the flexgrid:

      Facility                   Description  
          1                        Warehouse
          2                       Administration
          3                        Detail Center


Private sub Command1_click()

With FacilityFlexgrid
  .FixedRows = 1   'this sets aside the first row for the column Titles & headers
  .FormatString = BuildingNames  ' Building Names is a string variable containing Titles of the flexgrid.
 
  .RowSel = .Rows - 1  'This code determines number of rows in the FacilitiyFlexgrid and then subtracts 1. One is subtracted because the flexgrid starts at zero.  This code should put me on the last row of the flexgrid.
 
   FacilityFlexgrid.TextMatrix(FacilityFlexgrid.RowSel + 1, 0) = cbo_facilities.Column(0)
   FacilityFlexgrid.TextMatrix(FacilityFlexgrid.RowSel + 1, 1) = cbo_facilities.Column(1)
                           'The code above takes the first value of the combo box and put it in the next row of the Flexgrid.  The same with the second line.

End With


This Code only puts the record on row one in the flexgrid.  When user presses the command button for the next record to be placed in the flexgrid, it replaces what is already there.


Thanks,
The FireBird





0
Comment
Question by:BirdsOfFire1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
3 Comments
 
LVL 38

Expert Comment

by:PaulHews
ID: 7084355
With FacilityFlexgrid
 .FixedRows = 1   'this sets aside the first row for the column Titles & headers
 .FormatString = BuildingNames  ' Building Names is a string variable containing Titles of the flexgrid.
 .Rows = .Rows + 1 'ADDED LINE TO ADD A ROW
 .RowSel = .Rows - 1  'This code determines number of rows in the FacilitiyFlexgrid and then subtracts
1. One is subtracted because the flexgrid starts at zero.  This code should put me on the last row of
the flexgrid.
 
  FacilityFlexgrid.TextMatrix(FacilityFlexgrid.RowSel + 1, 0) = cbo_facilities.Column(0)
  FacilityFlexgrid.TextMatrix(FacilityFlexgrid.RowSel + 1, 1) = cbo_facilities.Column(1)
                          'The code above takes the first value of the combo box and put it in the
next row of the Flexgrid.  The same with the second line.

End With
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 7084360
You could also store the last row in a variable instead of selecting it using rowsel

dim intLastRow as integer
With FacilityFlexgrid
 .FixedRows = 1   'this sets aside the first row for the column Titles & headers
 .FormatString = BuildingNames  ' Building Names is a string variable containing Titles of the flexgrid.
 Rows = .Rows + 1 'ADDED LINE TO ADD A ROW
 intLastRow = .Rows - 1  'This code determines number of rows in the FacilitiyFlexgrid and then subtracts
1. One is subtracted because the flexgrid starts at zero.  This code should put me on the last row of
the flexgrid.
 
  FacilityFlexgrid.TextMatrix(intLastRow+ 1, 0) = cbo_facilities.Column(0)
  FacilityFlexgrid.TextMatrix(intLastRow + 1, 1) = cbo_facilities.Column(1)
                          'The code above takes the first value of the combo box and put it in the
next row of the Flexgrid.  The same with the second line.

End With
0
 
LVL 38

Accepted Solution

by:
PaulHews earned 200 total points
ID: 7084364
Except that I don't think you ever have to add one to the last row because .Rows - 1 should identify the last row:

FacilityFlexgrid.TextMatrix(intLastRow, 0) = cbo_facilities.Column(0)
 FacilityFlexgrid.TextMatrix(intLastRow, 1) = cbo_facilities.Column(1)
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question