i can't seem to get it to move next colum

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • steve proctor
    New Member
    • Dec 2010
    • 7

    i can't seem to get it to move next colum

    hi at the moment i can get this to load the contents of the first row,first column the number "1" into all the fields in the table "tblTransfe r2" so all the fields have the number "1" in it where the number "1" should only be in field "daynum" seatnum should read "A1" seatid should read "367" bookdate should be a date but skips past this bookedby should read "0" and cost should read "7" could anyone point me in the right direction???
    thanks
    Code:
    sql = "SELECT * from tbltransfer2"
     Set RecSet = dbAbbeytheatre.OpenRecordset(sql)
                    If Daynum = 0 Then
    '/////////////////////////////////////////////////////
             With MSFlexGrid1
                    n = n + 1
                   
                For I = 2 To .Rows - 1
    
                     strRowText = ""
    
                     For j = 0 To .cols - 1
    
                         strRowText = strRowText & .TextMatrix(I, j) & ";"
                            '////////////////////
                            RecSet.AddNew
                          RecSet!Daynum = MSFlexGrid1.TextMatrix(I, j)
                           RecSet!seatNum = MSFlexGrid1.TextMatrix(I + 1, 1)
                           RecSet!seatId = MSFlexGrid1.TextMatrix(I + 1, 2)
                             RecSet!bookdate = MSFlexGrid1.TextMatrix(I + 1, 3) 'didn't like date
                             RecSet!bookedby = MSFlexGrid1.TextMatrix(I + 1, 4)
                               RecSet!cost = MSFlexGrid1.TextMatrix(I + 1, 5)
                          RecSet.Update
                            '/////////////////////
                    Next j
    
                 Next I
    
             End With
    End If
    Last edited by Niheel; Dec 14 '10, 09:21 PM. Reason: added code tags.
  • Guido Geurs
    Recognized Expert Contributor
    • Oct 2009
    • 767

    #2
    I suppose the Flexgrid is like this:

    Code:
    Daynum | seatNum | seatId | bookdate | bookedby | cost |
       1        A1       367   15/12/2010     G.G       7
    In Your code You are loop through ROWs and COLs
    But for each COL You fill in ALL the fields of the record!
    So You Add a new record for each COL ! with the same data.

    You can't loop and add to different fields at the same time.
    You can only use the loop for: strRowText
    I think the code must be:

    Code:
    Dim ROW As Integer
    Dim COL As Integer
       sql = "SELECT * from tbltransfer2"
       Set RecSet = dbAbbeytheatre.OpenRecordset(sql)
       If Daynum = 0 Then
    '/////////////////////////////////////////////////////
          n = n + 1
          With MSFlexGrid1
             For ROW = 2 To .Rows - 1
                strRowText = ""
                For COL = 0 To .cols - 1
                   strRowText = strRowText & .TextMatrix(ROW, COL) & ";"
                Next COL
                '////////////////////
                RecSet.AddNew
                RecSet!Daynum = .TextMatrix(ROW, 0)
                RecSet!seatNum = .TextMatrix(ROW, 1)
                RecSet!seatId = .TextMatrix(ROW, 2)
                RecSet!bookdate = .TextMatrix(ROW, 3)  'didn't like date
                RecSet!bookedby = .TextMatrix(ROW, 4)
                RecSet!cost = .TextMatrix(ROW, 5)
                RecSet.Update
                '/////////////////////
             Next ROW
          End With
       End If

    Comment

    • steve proctor
      New Member
      • Dec 2010
      • 7

      #3
      hi and thanks for your help, i knew it had to hold the string of what was in the row but was not sure how??. you got it right, but it doesn't seem to like the date (bookdate) for some reason, it jumps at that point and so won't up date the other fields

      Comment

      • steve proctor
        New Member
        • Dec 2010
        • 7

        #4
        hi again,
        the problem lied in that i had them in the wrong order, now works! thumbs up and a huge big thanks !!!

        Comment

        Working...