Results 1 to 24 of 24

Thread: how do u show updates to a grid?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    New Zealand
    Posts
    268

    how do u show updates to a grid?



    Private Sub dbgResp_AfterUpdate()
    Dim selectS As String

    rstResults.MoveFirst
    While rstResults.EOF = False
    With rstResults
    .Edit
    !TimeDiff = "blah"
    .Update
    End With
    rstResults.MoveNext
    Wend
    'something missing here
    End Sub

    what i want this to do is, each time the user changes a cell on my dbgResp datagrid, i want it to change the timediff column to say blah, all good.

    but i want it to also update the grid, to show the changes, i tried doing a refresh, how can i make it show the new "blah" value?

  2. #2
    Fanatic Member rudvs2's Avatar
    Join Date
    Mar 2001
    Location
    NZ
    Posts
    935
    okay try doing something like this

    VB Code:
    1. Private Sub dbgResp_AfterUpdate()
    2. Dim selectS As String
    3.  
    4. rstResults.MoveFirst
    5.  
    6. Do Until  rstResults.EOF
    7.      
    8.     With rstResults
    9.           .Edit
    10.           !TimeDiff = "blah"
    11.           .Update
    12.      End With
    13.  
    14.      rstResults.MoveNext
    15. Loop
    16.  
    17. dbgResp.ReBind
    18.  
    19. End Sub

    you should use a do loop instead a while wend as a do loop is more robust and efficient method.

  3. #3
    PowerPoster Beacon's Avatar
    Join Date
    Jan 2001
    Location
    Pub Floor
    Posts
    3,188
    Well technically this is the fastest method of going through a recordset!
    Using rudvs2 code!
    VB Code:
    1. Private Sub dbgResp_AfterUpdate()
    2. Dim selectS As String
    3.  
    4. rstResults.MoveLast
    5. intRecCount=rstResults.RecordCount
    6. rstResults.MoveFirst
    7.  
    8. For intCounter=1 To intRecCount
    9.  
    10.     With rstResults
    11.           .Edit
    12.           !TimeDiff = "blah"
    13.           .Update
    14.      End With
    15.  
    16.   rstResults.MoveNext
    17. Next intCounter
    18.  
    19. dbgResp.ReBind
    20.  
    21. End Sub

    Bloddy nzenders taking over the place!

  4. #4
    Fanatic Member rudvs2's Avatar
    Join Date
    Mar 2001
    Location
    NZ
    Posts
    935
    Bloddy Aussies always having to have the last say

    lol

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    New Zealand
    Posts
    268

    im baaaack >=)

    whew, stupid lab technician made me make some stupid bags with the laminator, how rude, pfft

    neway, i turned that code into a for next an all very cool, but it still doesnt really help me, i tried had a rebind on it already, but it didnt seem to work

    ??

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    New Zealand
    Posts
    268
    in fact it as a rebind and a requery on it at the mo, have a look :



    For i = 1 To RecCount

    CurrDate = rstThisTest.Fields("Date")
    If IsNull(CurrDate) Then

    Else
    CurrTime = rstThisTest.Fields("Time")
    If IsNull(CurrTime) Then

    Else
    CurrDateTime = CurrDate + CurrTime
    CurrDateTime = CDate(CurrDateTime)
    TimeD = DateDiff("h", OrigDateTime, CurrDateTime)

    With rstThisTest
    .Edit
    !TimeDiff = TimeD
    .Update
    End With
    End If
    End If

    rstThisTest.MoveNext
    Next i

    rstThisTest.Requery
    dbgResp.ReBind

    End Sub

  7. #7
    Fanatic Member rudvs2's Avatar
    Join Date
    Mar 2001
    Location
    NZ
    Posts
    935
    just to be a pain in the rectum I reformatted your code again to make it easier to follow

    didnt fix your prob though

    VB Code:
    1. For i = 1 To RecCount
    2.  
    3. CurrDate = rstThisTest.Fields("Date")
    4.  
    5.     Select Case IsNull(CurrDate)
    6.  
    7.         Case Is = True
    8.             Exit Sub
    9.        
    10.         Case Else
    11.    
    12.         CurrTime = rstThisTest.Fields("Time")
    13.  
    14.         Select Case IsNull(CurrTime)
    15.        
    16.             Case Is = True
    17.                 Exit Sub
    18.  
    19.             Case Else
    20.                 CurrDateTime = CurrDate + CurrTime
    21.                 CurrDateTime = CDate(CurrDateTime)
    22.                 TimeD = DateDiff("h", OrigDateTime, CurrDateTime)
    23.  
    24.                 With rstThisTest
    25.                     .Edit
    26.                     !TimeDiff = TimeD
    27.                     .Update
    28.                 End With
    29.         End Select
    30.        
    31.     End Select
    32.  
    33.     rstThisTest.MoveNext
    34.  
    35. Next i
    36.  
    37. rstThisTest.Requery
    38. dbgResp.ReBind

  8. #8
    Banned Motxopro's Avatar
    Join Date
    Dec 2001
    Posts
    57
    yeah he's right

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    New Zealand
    Posts
    268
    :P te he he

  10. #10
    Banned Motxopro's Avatar
    Join Date
    Dec 2001
    Posts
    57
    hahaha

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    New Zealand
    Posts
    268
    nonono that's what u told me to do yesterday, it doesnt like that tho, comes up method or datamember not found, it doesnt reconise the .refresh method for my recordset

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    New Zealand
    Posts
    268
    mind u, when i go type

    dim rstblah as...

    it gives me recordset 3 times in the list of choices, does that mean they're all different things with the same name? how on earth am i ment to know which one to pick?

  13. #13
    PowerPoster Beacon's Avatar
    Join Date
    Jan 2001
    Location
    Pub Floor
    Posts
    3,188
    Sorry forgot!
    Are u using ado or dao or what??

    If adodb you should pick like:

    Private rs As ADODB.Recordset

    then set it!

    later b

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    New Zealand
    Posts
    268
    i think it must be dao, because now i get an errors on this line further back

    the old datatype mismatch

    Set rstThisTest = dbsRespiration_Testing.OpenRecordset(selectS)
    how can i turn it all into ado? is it a mission?

  15. #15
    PowerPoster Beacon's Avatar
    Join Date
    Jan 2001
    Location
    Pub Floor
    Posts
    3,188
    Depends how big your project is!

    Your not using any datacontrols are you?

    If not just check the Project/Referneces menu and see which data object is ticked!
    I.e Microsoft Data Object Library 4.0 = DAO

    Later
    b

  16. #16
    Fanatic Member rudvs2's Avatar
    Join Date
    Mar 2001
    Location
    NZ
    Posts
    935
    to turn it into ado from dao shouldnt be to muc hard work

    however if you are using a datacontrol (this uses dao) it might be a bit harder

    You could always try using the ado datacontrol (ughh) but i would recomend that you get stuck into writing the code yourself and using the ado dataobject

    to create aan ado connection you need to do the following


    First go to the references option in the priject menu of vb and add a reference to the Microsoft Activex Data Object Library

    VB Code:
    1. Dim Rs As ADODB.RecordSet
    2.  
    3. Set Rs = New ADODB.RecordSet
    4.  
    5. Rs.ActiveConnection = "Provider=Microsoft.JET.OLEDB.3.51;Data Source=" & your database path goes here
    6. Rs.Open "SELECT * From your table", , adOpenKeyset, adLockOptimistic
    7.  
    8. 'to retreive or set record values it is like this
    9. myVar = Rs.Fields("Myfield").Value
    10.  
    11. Rs.Fields("MyField").Value = myVar
    12.  
    13. 'you do not need to invoke an edit to replace values just place an update after changing them
    14.  
    15. Rs.Update
    16.  
    17. 'to add records
    18.  
    19. With Rs
    20.     .Add
    21.     .Fields("MyField").Value = myVar
    22. End With
    23.  
    24. 'there is of coarse a heap more than just that but that gives you the basics

  17. #17

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    New Zealand
    Posts
    268

    Talking chooice

    perfect, i could hug u! but i wont , now all i have to do is change all my blah to that

    funfun

    thanks heaps

  18. #18
    PowerPoster Beacon's Avatar
    Join Date
    Jan 2001
    Location
    Pub Floor
    Posts
    3,188
    *cough*
    show off
    *cough*


  19. #19

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    New Zealand
    Posts
    268
    shhh! dont breathe i think it's almost working

    i havent changed it all over tho, i realised i hadnt tired refreshing the ado it was connected to, ah ha

    so i have the timediff showing, only it's only behind, it only shows 1-3 or 4 ...

    ah, u guys are so lovely

  20. #20

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    New Zealand
    Posts
    268
    man that was full of typos, only it's ONE behind, and 1-3 OF 4
    hopeless

  21. #21

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    New Zealand
    Posts
    268

    still missing one

    im nearly there

    does anybody know why i might be not showing the last one? it only displays the time difference, after u update the next row, ie. when u have done rows 1,2 and 3, it will show the result of 1 and 2, once u do # 4, 1,2 and 3 are displayed

    Private Sub dbgResp_AfterUpdate()
    Dim OrigDateTime As Variant
    Dim CurrDateTime As Variant
    Dim RefreshBookmark As Variant
    Dim TimeD As Single
    Dim selectS As String
    Dim CurrTime As Variant
    Dim CurrDate As Variant
    Dim Bmark As Variant
    Dim RecCount As Integer
    Dim i As Integer

    'get initial date/time
    OrigDateTime = testdate
    OrigDateTime = OrigDateTime + " " + testtime
    OrigDateTime = CDate(OrigDateTime)

    rstThisTest.Requery

    For i = 1 To NumbTests

    CurrDate = rstThisTest.Fields("Date")
    If IsNull(CurrDate) Then

    Else
    CurrTime = rstThisTest.Fields("Time")
    If IsNull(CurrTime) Then

    Else
    CurrDateTime = CurrDate + CurrTime
    CurrDateTime = CDate(CurrDateTime)
    TimeD = DateDiff("h", OrigDateTime, CurrDateTime)

    With rstThisTest
    .Edit
    !TimeDiff = TimeD
    .Update
    End With
    End If
    End If

    rstThisTest.MoveNext
    Next i

    'rstThisTest.Requery
    adoResp.Refresh
    dbgResp.Refresh

  22. #22
    Fanatic Member rudvs2's Avatar
    Join Date
    Mar 2001
    Location
    NZ
    Posts
    935
    just a small peice of house keeping first

    when linking strings together instead of using the + operator you chould use the & operator use the + for numerical xpressions and math formulae. It makes it much easier when scanning your code to determin that you are simply joining 2 strings together and not trying to join add numerical values.

    it also means you can make say a var holding the number 1 and join it with a var holding the number 2 to make a value of 12 instead of 3 lol

    PS i have a feeling your problems may be coming from the fact that you are using a mish mash of datacontrols and dataobjects to manipulate the database. If you settle for using just one or the other things might start to settle down a bit

    but then I have been known to be wrong

  23. #23

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    New Zealand
    Posts
    268
    your probably right, damn me and my mishmash

    hehe, ooh &, i didnt know about that, that'll save me heaps of mucking around, heh, i can delete half me variables now

    i can send u that email either, it's the db, it's to big to fit on a disk or a hotmail thingy, i duno why, theres only 2 stupid tables :-/ argh

  24. #24
    Fanatic Member rudvs2's Avatar
    Join Date
    Mar 2001
    Location
    NZ
    Posts
    935
    rename your db for a mo run the visual data manager in the add ins menu of your vb and from file select compact database browse to your renamed db and select it for the new db name it will want put in the old name that your db was this will result in you having a compacted db with the original file name

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width