DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2005

    Unhappy MSFlexgrid and recordsets, code attached.

    I am really having a hard time understanding fully the MSFlexGrid and recordsets that are bound to them.

    I have created a database with 4 identical tables (except the name is different). I have the interface with 4 buttons to select the table they want to view at that time. I pass a SQL statement to the recordset and it populates the MSFlexgrid control with the data.

    I have another form that opens when the user double clicks a record in the grid and 5 textboxes get filled with the data from the row they selected.

    I want to be able to let the user edit any or all of the 5 text boxes and then click save and the program with update the record in the grid with the new info. Of course I need it to written back to the database instantly. I plan on this being a multi-user app.

    I have attached the full code of the project as it stands right now. Surely I am missing a very simple step in allowing the record to be changed, but my Googleing has not helped me solve this problem.

    Maybe someone can check out the code and give me some direction.

    Thanks all.
    Attached Files Attached Files

  2. #2
    Join Date
    Jun 2004
    morristown, TN


    You can do this 2 different ways:

    1. On the Save Button click create a new database connection and recordset objects. Make sure you have a primary key on the table you want to edit. Pass the recordset an Update sql statement i.e. "Update Business Set Name = """ & me.txtEditName.text & ""' Where ID = " & frmMain.MSFlexGrid1.bookmark

    2. Or you can create an ADODC object on the edit form and use the ADODC.Update before you update the fields that have need updating.

    Hope this helps!

  3. #3
    Join Date
    Jun 2004
    Houston area
    The way *I* did it is, when the user clicks the grid, I do this:
    If .TextMatrix(0, 0) = "" Then Exit Sub
    If .Row > 0 Then
        HourlyRow = .Row
        cmdEditHourly.Enabled = True
        cmdDeleteHourly.Enabled = True
        HourlyRow = 0
        cmdEditHourly.Enabled = False
        cmdDeleteHourly.Enabled = False
    End If
    This keeps track of the row the user clicked on. Then, in the edit button click event, populate the text boxes (or comboboxes in my case). Then, in the save button's click event I have this:

    Private Sub cmdSaveHourly_Click()
    Dim rs As Recordset
    HourlyMissingData = False
    If cboJobNameHourly = "" Then
        MsgBox ("Please indicate a Job Name.")
        HourlyMissingData = True
        Exit Sub
    End If
    If txtDate.Text = "__/__/__" Then
        MsgBox ("Please enter a date for this entry.")
        HourlyMissingData = True
        Exit Sub
    End If
    If cboPersonnelHourly = "" Then
        MsgBox ("Please choose an employee for this entry.")
        HourlyMissingData = True
        Exit Sub
    End If
    If cboTaskNameHourly = "" Then
        MsgBox ("Please choose a task/duty for this entry.")
        HourlyMissingData = True
        Exit Sub
    End If
    If txtRegHoursHourly = "0" Or txtRegHoursHourly = "" Then
        MsgBox ("Please enter number of hours for this duty.")
        HourlyMissingData = True
        Exit Sub
    End If
    If cboRateHourly = "" Then
        MsgBox ("Please indicate hourly rate.")
        HourlyMissingData = True
        Exit Sub
    End If
    If HourlyAddEdit = mEdit Then
    If (MsgBox("Save changes to record for " & cboJobNameHourly.Text & "?", vbYesNo)) = vbNo Then Exit Sub
    Set rs = gLookUpsDB.OpenRecordset("select * from JOBSUMMARY where [task category] = 'HOURLY' order by [JobName],[datecompleted], [employee name];") 'This is the same SQL statement that I used to populate the grid
    End If
    If HourlyAddEdit = mAdd Then
    Set rs = gLookUpsDB.OpenRecordset("select * from JOBSUMMARY")
    End If
    With rs
        If HourlyAddEdit = mEdit Then
            .Move (HourlyRow - 1) 'I don't know why this works!
        ElseIf HourlyAddEdit = mAdd Then
        End If
    !JobName = cboJobNameHourly.Text
    !DateCompleted = Format(txtDate.Text, "mm/dd/yy")
    ![Employee Name] = cboPersonnelHourly.Text
    If Not IsNull(cboAreaHourly.Text) Then !Unit = cboAreaHourly.Text Else !Unit = ""
    !Task = cboTaskNameHourly.Text
    ![Task Category] = "HOURLY"
    ![LaborHours] = txtRegHoursHourly.Text
    ![HourlyRateType] = cboRateHourly.Text
    End With
    End Sub
    Hope this helps!


    P.S. I don't have my glasses on so I can't read what I just posted! LOL
    A balanced diet is a cookie in each hand.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center