PDA

Click to See Complete Forum and Search --> : Requerying a MSHFlexgrid


Julian B
Aug 22nd, 2000, 06:39 AM
When I am trying to add/edit/delete to a MSHflexgrid with the following code it will not update the database, unless I stop the program running and restart it. I would be grateful if anyone can see anything that is blatantly obvious with this code that would prevent the database to refresh correctly.


Private Sub cmdToDoAdd_Click()
With DataEnvironment1.rsComToDo
.Close
.Open "select * from todo", , adOpenDynamic
.AddNew
.Fields("ProjectID") = DataEnvironment1.rsComProjects.Fields("projectID")
End With
DataEnvironment1.rsComToDo.AddNew
frmToDo.Show 1


DataEnvironment1.rsComProjects.Requery
Set myRS = DataEnvironment1.rsComProjects.Fields("comtodoview").Value


End Sub

_---------------------------------------------------------

Private Sub cmdToDoDelete_Click()
flxToDoItems.Col = 0
tempval = "" & flxToDoItems.Text

flxToDoItems.ColSel = 4
If IsNumeric(tempval) Then
With DataEnvironment1.rsComToDo
.Close
.Open "select * from todo where uniqueID = " & tempval

If .RecordCount > 0 Then
result = MsgBox("Are you sure you want to delete the item: " & DataEnvironment1.rsComToDo.Fields("itemname").Value, vbOKCancel, "delete")

If result = 1 Then DataEnvironment1.rsComToDo.Delete

DataEnvironment1.rsComProjects.Requery

Set myRS = DataEnvironment1.rsComProjects.Fields("comtodoview").Value

End If



End With


-----------------------------------------------------------

Private Sub cmdToDoEdit_Click()
flxToDoItems.Col = 0
tempval = "" & flxToDoItems.Text

flxToDoItems.ColSel = 4
If IsNumeric(tempval) Then
With DataEnvironment1.rsComToDo
.Close
.Open "select * from todo where uniqueID = " & tempval
If .RecordCount > 0 Then
frmToDo.Show 1
End If
End With
End If

End Sub

----------------------------------------------------------

Many Thanks

Bill Crawley
Aug 23rd, 2000, 11:21 AM
Hi,

A couple of things to try:
Sometimes with a flexgrid Requery also requires a rebind. Try adding rebind as well.

Secondly You may also need to use the update method since for instance in your add new section your have a .addnew method with no coresponding update. This probably means that the data has been logically posted back to the database but not phsically posted. When you close the program it performs an explicit update this is more than likeky due to the Database setup since normally a rollback would occur.