Advertisement
4_2005-2006 Databases/ Data Access/ DAO/ ADO #154273

MS FlexGrid Tutorial

This program is designed to teach the user how to load data into a FlexGrid from an Access database and then manipulate the FlexGrid to perform typical database actions such as Add, Edit, Sort, and Delete. The database manipulations are executed with ADO methods

AI

Résumé par IA: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Code source
original-source
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>FlexGrid Tutorial</title>
</head>
<body>
<table border="0" width="100%">
 <tr>
  <td width="100%">
<h1 align="center">FlexGrid Tutorial</h1>
<p><font color="#0000FF">&nbsp;This program is designed to&nbsp; teach the user how to load
data into a FlexGrid from a database and then manipulate the FlexGrid to       perform typical database actions       such as Add, Edit, Sort, and
Delete.</font><br>
</p>
<h2>Part One - Setting Up the FlexGrid</h2>
<p>&nbsp;</p>
<h3>1st Step:&nbsp;</h3>
<p><font color="#0000FF">A. Go to the Project Menu Tab and select Components.<br>
B. Add the Microsoft Flexgrid Control 6.0</font>
</p>
<p align="center"><a href="http://jerry_m_barnes.tripod.com/VBImages/component.jpg">Picture
One</a>
</p>
<p align="left"><font color="#0000FF"><br>
C. Go to the Project menu Tab and select References.<br>
D. Add Microsoft ActiveX Data Objects 2.1 Libray.</font>
</p>
<p align="center"><br>
</p>
<p align="center"><a href="http://jerry_m_barnes.tripod.com/VBImages/reference.jpg">Picture
Two</a>
</p>
<h3>2nd Step</h3>
<p><font color="#0000FF">A. Rename the form to frmMain.<br>
B. Change the form's Caption To "FlexGrid Tutorial&quot;<br>
C. Rename the project to FlexGridTutorial.<br>
D. Add a FlexGrid to the form.<br>
E. Using the property window, Rename the FlexGrid to fg.<br>
</font></p>
<p align="center">&nbsp;</p>
<p align="center"><font color="#0000FF"><a href="http://jerry_m_barnes.tripod.com/VBImages/frmmain01.jpg">Picture
Three</a></font></p>
<h3>3rd Step:</h3>
<p><font color="#0000FF"><br>
A. Declare a connection and recordset object (Code Follows).<br>
B. In the Form_Load Event, open the connection and recordset (Code Follows).<br>
C. Also, from the Form_Load Event, call the  LoadFG Procedure (This is not written yet-  It will be the next step).</font><br>
<br>
Option Explicit<br>
Dim WithEvents cn As ADODB.Connection<br>
Dim WithEvents rs As ADODB.Recordset<br>
<br>
Private Sub Form_Load()<br>
<br>
  Dim strConnect As String<br>
<br>
<font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp; </font>strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &amp; _<br>
<font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font>App.Path &amp; "\fgtutorial.mdb"<br>
<br>
<font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp; </font>Set cn = New ADODB.Connection<br>
<font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp; </font>cn.CursorLocation = adUseClient<br>
<font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp; </font>cn.Open strConnect<br>
<br>
<font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp; </font>Set rs = New ADODB.Recordset<br>
<font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp; </font>rs.CursorLocation = adUseClient<br>
<font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp; </font>rs.CursorType = adOpenForwardOnly<br>
<font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp; </font>rs.LockType = adLockPessimistic<br>
<font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp; </font>rs.Source = "SELECT * FROM [Employees]"<br>
<font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp; </font>rs.ActiveConnection = cn<br>
<font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp; </font>rs.Open<br>
<br>
<font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp; </font>Call LoadFG<br>
End Sub<br>
<br>
</p>
<h3>4th Step:&nbsp;<br>
</h3>
<p><font color="#0000FF">A. Write the LoadFG Procedure as follows</font><br>
<br>
Private Sub LoadFG()<br>
<br>
<font color="#008000">  'The AllowUserResizing property<br>
  '  allows the user to resize<br>
  '  the columns and rows during<br>
  '  runtime when it is set to<br>
  '  flexResizeBoth.<br>
  '  The other options are:<br>
  '      flexResizeColumns<br>
  '      flexResizeNone<br>
  '      flexResizeRows</font><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp; fg.AllowUserResizing = flexResizeBoth<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'Set the number of columns by using the<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  number of fields plus one. One is added<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  in order to leave the first column<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  (row headers) blank. Note that you can<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  use any number for the number of columns<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  if you want to leave certain data out.<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  For example, if you only want to use<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  three fields out of ten, set fg.cols<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  equal to 4.<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp; fg.Cols = rs.Fields.Count + 1<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'Set the number of rows equal to one<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  for the time being. We do this since<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  we are going to be adding the column<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  titles first. When we are finished<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  adding the column headers, we will<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  populate the rest of the table.<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp; fg.Rows = 1<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp; Dim i As Integer <font color="#008000"> 'This will be a counter.</font><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'Fill in the column headings with the<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  field names from the recordset. Note<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  that we are using the field names<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  from the database for the column<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  headers. You could<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  assign whatever header you like by<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  simply doing something like the<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  following:<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'    fg.Col = 0<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'    fg.Text = "First Column"<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">' fg.</font><font color="#008000">Col = 1<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'    fg.Text = "Second Column"<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'    etc.<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'Row 0 is the first row (and only row). It is<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  where the headers will be placed.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp; fg.Row = 0<br>
&nbsp;&nbsp;&nbsp;&nbsp; For i = 0 To rs.Fields.Count - 1<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'Move to column i. Remember that the<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  first column is left blank so<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  we shift over 1.<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fg.Col = i + 1<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'The following line aligns the cell.<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  The other options for alignment are:<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  flexAlignLeftTop 0<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  flexAlignLeftCenter 1<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  flexAlignLeftBottom 2<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  flexAlignCenterTop 3<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  flexAlignCenterCenter 4<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  flexAlignCenterBottom 5<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  flexAlignRightTop 6<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  flexAlignRightCenter 7<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  flexAlignRightBottom 8<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  flexAlignGeneral 9</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fg.ColAlignment(i) = flexAlignLeftCenter<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'Set the text in the current cell<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  to the field name.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fg.Text = rs.Fields(i).Name<br>
&nbsp;&nbsp;&nbsp;&nbsp; Next<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'This would be a good time to run
the project<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">' to see what you have.
Try to resize the<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">' columns using the mouse.</font><br>
<br>
<br>
<font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp; 'Fill in the data from the db into the<br>
&nbsp;&nbsp;&nbsp;&nbsp; '  grid.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp; Do While Not rs.EOF<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'Add a row to the FlexGrid everytime<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  the database goes to another row.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fg.Rows = fg.Rows + 1<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'Move to last row to add data.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fg.Row = fg.Rows - 1<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'Move to every cell in the row<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '  and fill it in with the<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '  corresponding value from the<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '  database.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For i = 0 To rs.Fields.Count - 1<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<font color="#008000">'Remember that the<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<font color="#008000">'  first column is left blank so<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<font color="#008000">'  we shift over 1.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
fg.Col = i + 1<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
fg.Text = rs(i).Value &amp; ""<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'Move to the next record.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rs.MoveNext<br>
&nbsp;&nbsp;&nbsp;&nbsp; Loop
</p>
<p>&nbsp;
</p>
<p>
&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'The first column is the headers for the<br>
</font>
&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  rows. Change its width so that<br>
</font>
&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  it is not as wide as the other columns.<br>
</font>
&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  You could change all column widths<br>
</font>
&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  with a for next loop.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp; fg.ColWidth(0) = 500<br>
<font color="#008000"><br>
</font>&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'The FlexGrid is loaded.<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  Now is a good time to run the<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  the program and view your results.</font><br>
End Sub
<br>
<br>
</p>
<h2>Part Two - Adding Common Database Functions
</h2>
<h3>1st Step
</h3>
<p><font color="#0000FF">A. Go to the Tools Menu and select Menu Editor.<br>
B. Add the following menus:<br>
&nbsp;File<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit<br>
&nbsp;Edit<br>
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;Add<br>
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;Delete<br>
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;Sort<br>
&nbsp;Properties of Menus:<br>
&nbsp;<u>Name</u>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<u>Caption</u><br>
&nbsp;mnuFile&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&amp;File<br>
&nbsp;mnuFileExit&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
E&amp;xit<br>
&nbsp;mnuEdit&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&amp;Edit<br>
&nbsp;mnuEditAdd&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &amp;Add<br>
&nbsp;mnuEditDelete&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &amp;Delete<br>
&nbsp;mnuEditSort&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &amp;Sort</font>
</p>
<p align="center">&nbsp;
</p>
<p align="center"><a href="http://jerry_m_barnes.tripod.com/VBImages/menueditor.jpg">Picture
Four</a>
</p>
<p><font color="#0000FF">
C. Program in the follwing procedures for the mnuFileExit_Click event.</font><br>
<br>
<br>
<br>
Private Sub mnuFileExit_Click()<br>
<br>
&nbsp;&nbsp;&nbsp;
<font color="#008000">  'Tidy up the objects floating in memory.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp; Set cn = Nothing<br>
&nbsp;&nbsp;&nbsp;&nbsp; Set rs = Nothing<br>
&nbsp;&nbsp;&nbsp;&nbsp; End<br>
End Sub
</p>
<h3><br>
2nd Step
</h3>
<p><font color="#0000FF">A. Add the following code for the delete procedure.<br>
</font><br>
Private Sub mnuEditDelete_Click()<br>
<br>
  Dim intChoice As Integer<br>
  Dim intEmployeeID As Integer<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'Move to column 0 so that we can get<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  the employeeid number. This will<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  be used to delete the record from<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  the database.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp; fg.Col = 1<br>
&nbsp;&nbsp;&nbsp;&nbsp; intEmployeeID = fg.Text<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'find the desired record and kill it.<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp; rs.MoveFirst<br>
&nbsp;&nbsp;&nbsp;&nbsp; rs.Find ("EmployeeID Like '" &amp; intEmployeeID &amp; "'")<br>
&nbsp;&nbsp;&nbsp;&nbsp; intChoice = MsgBox("Are you sure you want to delete " &amp; _<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "the record of " &amp; rs.Fields("FirstName").Value &amp; " " &amp; _<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
rs.Fields(&quot;LastName&quot;).Value &amp; &quot;?&quot;, vbYesNo, "Delete?")<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'Confirm Delete<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp; If intChoice = vbYes Then<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rs.Delete<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'This command does not delete the row from<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  database. It just removes the row.<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  from the flexgrid.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fg.RemoveItem (fg.Row)<br>
&nbsp;&nbsp;&nbsp;&nbsp; Else<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox "Delete Cancelled", vbOKOnly, "Cancelled"<br>
&nbsp;&nbsp;&nbsp;&nbsp; End If
</p>
<p>&nbsp;
</p>
<p><font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp; 'Potential Problem: You cannot remove the last<br>
&nbsp;&nbsp;&nbsp;&nbsp; '  non-fixed row from the flexgrid. Try it.<br>
&nbsp;&nbsp;&nbsp;&nbsp; '  Delete all rows. When you delete the last<br>
&nbsp;&nbsp;&nbsp;&nbsp; '  one, it is deleted from the database, but<br>
&nbsp;&nbsp;&nbsp;&nbsp; '  not from the flexgrid.<br>
&nbsp;&nbsp;&nbsp;&nbsp; 'I do not know the best solution for this<br>
&nbsp;&nbsp;&nbsp;&nbsp; '  problem, but I do have temporary solution<br>
&nbsp;&nbsp;&nbsp;&nbsp; '  that works for me.<br>
&nbsp;&nbsp;&nbsp;&nbsp; '  Replace fg.RemoveItem (fg.Row) with the<br>
&nbsp;&nbsp;&nbsp;&nbsp; '    following code:</font><br>
<font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp; </font>'<br>
<font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp; </font>'  if rs.RecordCount &lt;> 0 then<br>
<font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp; </font>'<font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font>
fg.RemoveItem(fg.Row)<br>
<font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp; </font>'  Else<br>
<font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp; </font>'&nbsp;<font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp;
</font>fg.RowHeight(fg.Row) = 0<br>
<font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp; </font>'  End If<br>
<font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp; </font>'<br>
<font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp; 'The problem with this fix is that the row still<br>
&nbsp;&nbsp;&nbsp;&nbsp; '  exists in the flexgrid until the app is<br>
&nbsp;&nbsp;&nbsp;&nbsp; '  closed. When it is opened again, the<br>
&nbsp;&nbsp;&nbsp;&nbsp; '  row will not be there.</font><br>
End Sub
</p>
<h3>3rd Step
</h3>
<p><font color="#0000FF">A. Program the following code for the    mnuEditSort_Click procedure</font>
</p>
<p>Private Sub mnuEditSort_Click()<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008000"> 'This will sort the flexgrid according to<br>
&nbsp;&nbsp;&nbsp;&nbsp; '  the column that is selected. We have<br>
&nbsp;&nbsp;&nbsp;&nbsp; '  selected sort ascending. The other options<br>
&nbsp;&nbsp;&nbsp;&nbsp; '  are given below.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp; fg.Sort = 1<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp; '<font color="#008000">flexSortNone = 0<br>
&nbsp;&nbsp;&nbsp;&nbsp; 'flexSortGenericAscending = 1<br>
&nbsp;&nbsp;&nbsp;&nbsp; 'flexSortGenericDescending = 2<br>
&nbsp;&nbsp;&nbsp;&nbsp; 'flexSortNumericAscending = 3<br>
&nbsp;&nbsp;&nbsp;&nbsp; 'flexSortNumericDescending = 4<br>
&nbsp;&nbsp;&nbsp;&nbsp; 'flexSortStringNoCaseAsending = 5<br>
&nbsp;&nbsp;&nbsp;&nbsp; 'flexSortNoCaseDescending = 6<br>
&nbsp;&nbsp;&nbsp;&nbsp; 'flexSortStringAscending = 7<br>
&nbsp;&nbsp;&nbsp;&nbsp; 'flexSortStringDescending = 8<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp; 'It it not a bad idea to add a menu item<br>
&nbsp;&nbsp;&nbsp;&nbsp; '  for sort descending and sort ascending.</font>
</p>
<p><font color="#008000"><br>
</font>
<font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#008000">'Potential Problem: The first column is fixed.<br>
</font><font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#008000">'  You cannot select a cell in the first column.<br>
</font><font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#008000">'<br>
</font><font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#008000">'    fg.Col = 0<br>
</font><font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#008000">'    fg.Sort = 1<br>
</font><font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#008000">'  but this takes away the use of the mouse<br>
</font><font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#008000">'  in selecting a column.<br>
</font><font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#008000">'  Another solution is to leave the first column<br>
</font><font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#008000">'  empty when you are loading the table. Start<br>
</font><font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#008000">'  with 1 instead of 0 when filling in values<br>
</font><font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#008000">'  on the row. This is the solution we used.</font><br>
End Sub
</p>
<h3>4th Step
</h3>
<p><font color="#0000FF">In this step we will add a new row to the grid. Adding a row is easy. You just&nbsp;
put in fg.AddItem "". This adds a blank row. It doesn't do any good to add a row unless you can put data into your
database though.&nbsp; It is a lot harder to    get this done.&nbsp;</font>
</p>
<p align="left"><font color="#0000FF"><br>
A. Add a text box to the form named txtCell.&nbsp; Set the text property to "",
set the    visible property to false,
and the border style to none.</font>
</p>
<p align="center"><font color="#0000FF"><br>
</font>
</p>
<p align="center"><font color="#0000FF"><a href="http://jerry_m_barnes.tripod.com/VBImages/frmmain02.jpg">Picture
Five</a></font>
</p>
<p><font color="#0000FF">B. Add the following code for the add procedure.</font>
</p>
<p>Private Sub mnuEditAdd_Click()<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'Add a new record to the DB. We need to do this<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  in order to get the next Employee ID number<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  since the EmployeeID is an autonumber field.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rs.AddNew<br>
<br>
<font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'In this particular database, FirstName and<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '  lastname are required fields. Since the<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '  user needs to enter values for them, we<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '  use empty strings for the values<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '  until they can be filled in.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rs.Fields("FirstName").Value = " "<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rs.Fields("LastName").Value = " "<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'Save the record. It would be nice if escape<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  could cancel the update, but I haven't<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  got that part figured out yet.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rs.Update<br>
<br>
<font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'Move to the last record so that we<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '  can get the employee ID.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rs.MoveLast<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'The format: AddItem String, Index<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  the string is whatever message goes in the<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  first column. The Index is row where<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  the new row is inserted. If left blank<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  the row is adding onto the end.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fg.AddItem ""<br>
<font color="#008000"><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'Put the Employee ID in the table.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '  Go to the last row and first column.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fg.Row = fg.Rows - 1<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fg.Col = 1<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'Add the EmployeedID. Note that a permanent<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  record has been created in the database.<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  If nothing is typed in the fields then<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  a record exists with just an employee id.</font><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fg.Text = rs.Fields("EmployeeID").Value<br>
<br>
<font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'Call the MoveTextBox Procedure. It has not<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '  been written yet.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Call MoveTextBox<br>
End Sub<br>
<br>
<font color="#0000FF">C. Go to the declarations section and add thefollowing declarations.</font>
</p>
<p><br>
&nbsp;Dim mblnLoaded As Boolean<br>
&nbsp;Dim mblnMouse  As Boolean<br>
<br>
<font color="#0000FF">&nbsp;mblnLoaded is going to be used to load the grid.<br>
&nbsp;mblnMouse is going to be used to determine if a cell has been clicked on.</font><br>
<br>
<font color="#0000FF">D. Now go to the Form_Load event. Before the the call to LoadGrid, set mblnLoaded to false.&nbsp;
After the call to LoadGrid, set mblnLoaded = True.&nbsp; It should look like the
following.</font>
</p>
<p><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mblnLoaded = False<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Call LoadFG<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mblnLoaded = True<br>
<br>
<font color="#0000FF">This is necessary in order to keep the cell from being filled
with null values with the EnterCell and LeaveCell events coming up.</font><br>
<br>
<br>
<font color="#0000FF">E. Program in the MoveTextBox Procedure.</font><br>
<br>
Private Sub MoveTextBox()<br>
<font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'This procedure moves a textbox over the<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '  selected cell, makes it visible, sets<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '  its text equal to the cell's text, &amp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '  gives it the focus. I got the idea<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '  for this from:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '  www.msdn.microsoft.com</font><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'Make the textbox visible.<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; txtCell.Visible = True<br>
<br>
<font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'Move the text box over the selected cell.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim inthold<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; inthold = fg.Row<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; inthold = fg.Col<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; txtCell.Left = fg.Left + fg.CellLeft<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; txtCell.Top = fg.Top + fg.CellTop<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; txtCell.Height = fg.CellHeight<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; txtCell.Width = fg.CellWidth<br>
<br>
<font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'Set the text in the textbox equal to the<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '  text in the selected cell.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; txtCell.Text = fg.Text<br>
<br>
<font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'Activate the cell.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; txtCell.SetFocus<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Len(txtCell.Text) > 0 Then<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; txtCell.SelStart = 0<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; txtCell.SelLength = Len(txtCell.Text)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br>
<font color="#008000"><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'The following line will be important later.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '  If two controls occupy the same space,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '  Zorder describes which control is on top.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '  Zorder (0) brings a control to the front.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; txtCell.ZOrder (0)<br>
End Sub<br>
<br>
<font color="#0000FF">F. Add the following five procedures.<br>
</font><br>
Private Sub fg_EnterCell()<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'First<br>
</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'Do not manipulate cell values until<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  the grid is loaded.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If mblnLoaded = True Then<br>
<font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
'Assign cell value to the textbox</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; txtCell.Text = fg.Text<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br>
End Sub<br>
<br>
Private Sub fg_LeaveCell()<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008000"> 'Second<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'Do not manipulate cell values until<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '  the grid is loaded.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If mblnLoaded = True Then<br>
<font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
'Assign textbox value to the cell</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fg.Text = txtCell.Text<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; txtCell.Text = ""<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br>
End Sub<br>
<br>
Private Sub fg_MouseDown(Button As Integer, Shift As Integer, _<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x As Single, y As Single)<br>
<font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'Third<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'If the mouse is clicked set mblnMouse to True.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mblnMouse = True<br>
<br>
<font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'Assign the textbox with the cell value.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fg.Text = txtCell.Text<br>
<br>
<font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'Move the textbox to the desired postion.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MoveTextBox<br>
End Sub<br>
<br>
Private Sub txtCell_KeyDown(KeyCode As Integer, Shift As Integer)<br>
<font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'Fourth<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'This procedure will allow the user to leave<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '  a cell with the enter key.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If KeyCode = 13 Then<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SendKeys "{TAB}"<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br>
End Sub<br>
<br>
Private Sub Form_Activate()<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'Fifth</font><br>
<br>
<font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'The procedure set the focus to the first<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '  cell when the form activates. This<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '  could be inconvienent if the user changes<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '  forms while leaving this one open. Boolean<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '  variables could be used to avoid this.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fg.Col = 1<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fg.Row = 1<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MoveTextBox<br>
End Sub<br>
<br>
<font color="#0000FF">'G. Enter the following procedure. Basically this procedure moves the text box when
you tab.</font><br>
<br>
Private Sub Txtcell_LostFocus()<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'This sub has not been programmed yet.<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  It will be programmed next.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Call SaveRecord<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'If the user clicks on a cell, go<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  to the cell. See the MouseDown</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  Proc earlier. Leave.<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If mblnMouse = True Then<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mblnMouse = False<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Sub<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'Move to the new column and send the<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '  text box there.<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'If you're not at the end of the column,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '  move to next column.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If fg.Col &lt;= fg.Cols - 2 Then<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fg.Col = fg.Col + 1<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MoveTextBox<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else <font color="#008000"> 'If you're at the end of a row,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' go to the last row unless you<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' are on the last row.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If fg.Row + 1 &lt; fg.Rows Then<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
fg.Row = fg.Row + 1<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
fg.Col = 1<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Call MoveTextBox<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br>
End Sub<br>
<br>
<font color="#0000FF">H. Enter the SaveRecord Procedure. This procedure saves the record whenever
you leave the cell.</font><br>
<br>
Private Sub SaveRecord()<br>
<font color="#008000"><br>
  'If the cell and textbox are different,<br>
  '  save the new value.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If txtCell.Text &lt;> fg.Text Then<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim intEmployeeID As Integer<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim inthold As Integer<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'Hold the current col position.<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; inthold = fg.Col<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'Move to the first column in order<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  to get the Employee ID.<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fg.Col = 1<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; intEmployeeID = fg.Text<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'Move back to the original column.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fg.Col = inthold<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'Assign the text from the textbox to<br>
</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
'  the cell.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fg.Text = txtCell.Text<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'Find the record with the specified<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'  employee id.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rs.MoveFirst<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rs.Find ("EmployeeID Like '" &amp; intEmployeeID &amp; "'")<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'Change the value and save the record.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rs.Fields(fg.Col - 1).Value = fg.Text<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rs.Update<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br>
End Sub<br>
<br>
<font color="#0000FF">Run the program now. Click on a cell and scroll. You will notice that the cell moves and the
text box stays where it is. This is unacceptable. so lets fix it.</font><br>
<br>
<font color="#0000FF">I. The following procedure will take care of this    problem.</font><br>
<br>
Private Sub fg_Scroll()<br>
<br>
<font color="#008000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'Whenever a scroll occurs, automatically<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '  put txtCell on top.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; txtCell.ZOrder (0)<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#008000">'If the current cell is scrolled off screen<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' then put it behind the grid.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If fg.ColPos(fg.Col) &lt; 0 Then<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; txtCell.ZOrder (1)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ElseIf fg.ColPos(fg.Col) > 4500 Then<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; txtCell.ZOrder (1)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else <font color="#008000">  'If the current cell comes back<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '  on the screen bring it to<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '  the front.</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; txtCell.Left = fg.CellLeft + fg.Left<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br>
End Sub<br>
<br>
<font color="#0000FF">Another problem has arisen since we started using the floating text box. Run the program
and sort a column. The text box does not move or contain the value of the cell that it is over after the sort is performed.</font><br>
<br>
<font color="#0000FF">J. Fix the Sort Problem by going to the mnuEditSort_Click Procedure and inserting&nbsp;
the following two lines after fg.Sort = 1</font><br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fg.Row = 1<br>
&nbsp;&nbsp;&nbsp;&nbsp; Call MoveTextBox<br>
<br>
<br>
<br>
</p>
<h3 align="left">Afterward:<br>
</h3>
<p align="left"><font color="#0000FF">This project took a lot longer than I presumed
it would. My goal was to make this table look and behave like an Access table. It is
close now but still has many features to be added.&nbsp; If I have time I may
add these.<br>
<br>
The project took a while because every time I added a new feature, it would affect another part
of the program. This led to many changes and revisions.&nbsp; I think that the the version that I have now
works fairly well. There are some features that I did not get to such as cutting
columns or rows and pasting them at a different position.&nbsp;&nbsp;<br>
<br>
There are also some features that I did not know how to  implement. I could not import pictures
from a database into the FlexGrid correctly (which would be a cool feature). I would also
like to be able to cancel an add new record correctly. In Access with autonumber, the
record number will not be saved until another<br>
field is completed. It would be a great help if someone would post solutions to these  problems.</font><br>
<br>
</p>
<p align="right">
<br>
<a href="mailto:[email protected]">[email protected]</a>
</p>
  </td>
 </tr>
</table>
<h1 align="center">&nbsp;</h1>
</body>
</html>
Commentaires originaux (3)
Récupéré via Wayback Machine