Results 1 to 7 of 7

Thread: how to i increase the (column,row) of a specfic value thanks!!

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2007
    Posts
    10

    how to i increase the (column,row) of a specfic value thanks!!

    this is my code for counting:
    Code:
      
       Dim sql As String
       Dim strCount As String
       sql = "Select Count(*) from Table1 Where BOOKNAME='" & tempBook & "'"
       Data1.RecordSource = sql
       Data1.Refresh
       strCount = Data1.Recordset.Fields(0)
       Data1.Refresh
    this is the part where i can ONLY INCREASE the availibility column 1 by 1:

    when i add the first book, it will show 1
    when i add the second book, for the first book it will show 2, but for the second book it will still show 1.

    when i add the third book, for the first book it will show 3, for the second book it will show 2 and for the book i just added in it will show 1.

    it looks like that:

    BOOKNAME----------TAGID-----------TAGCONTENT---------AVALIBILITY
    hi------------------------S----------------------S--------------------3
    hi------------------------S----------------------S--------------------2
    hi------------------------S----------------------S--------------------1


    what i want is that when i add e.g. the 4th book, all the AVALIBILITY will be 4. when i add the 5th book, all will be 5.

    this is my current code:
    Code:
    Private Sub Command1_Click()
     If Text1.Text = "" Or Text2.Text = "" Or Text3.Text = "" Then
       errormsg = MsgBox("ALL FIELDS MUST CONTAIN DATA!!")
     Else
        Data1.Recordset.AddNew
        Data1.Recordset.Fields(0).Value = Text1.Text
        Data1.Recordset.Fields(1).Value = Text2.Text
        Data1.Recordset.Fields(2).Value = Text3.Text
        'Data1.Recordset.Fields(3).Value =
        Data1.Recordset.Update
       End If
       
       Dim tempBook As String
       tempBook = Text1.Text
      
       MsgBox "Book has been added!!"
       
       Data1.Recordset.MoveFirst
            Do While Not Data1.Recordset.EOF
                Data1.Recordset.Edit
                If UCase(Data1.Recordset![BOOKNAME]) = UCase(tempBook) Then
                    Data1.Recordset![AVALIBILITY] = Data1.Recordset![AVALIBILITY] + 1
                Else
                    Data1.Recordset![AVALIBILITY] = 1
                End If
                Data1.Recordset.Update
                Data1.Recordset.MoveNext
            Loop
            
             
            
        
       
       Dim sql As String
       Dim strCount As String
       sql = "Select Count(*) from Table1 Where BOOKNAME='" & tempBook & "'"
       Data1.RecordSource = sql
       Data1.Refresh
       strCount = Data1.Recordset.Fields(0)
       Data1.Refresh
            
       Dim strMsg As String
       strMsg = "Book Availability is " & strCount
       Text1.Text = ""
       Text2.Text = ""
       Text3.Text = ""
       Text4.Text = strMsg

    may i know how/where could i edit it thanks=)

  2. #2
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,510

    Re: how to i increase the (column,row) of a specfic value thanks!!

    Would his work?

    Code:
    Data1.Recordset![AVALIBILITY] = Data1.Recordset![AVALIBILITY] = Data1.Recordset.Recordcount

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2007
    Posts
    10

    Re: how to i increase the (column,row) of a specfic value thanks!!

    thanks guys i shall go back to try tml !! will update yea!

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: how to i increase the (column,row) of a specfic value thanks!!

    Quote Originally Posted by wes4dbt
    Would his work?

    Code:
    Data1.Recordset![AVALIBILITY] = Data1.Recordset![AVALIBILITY] = Data1.Recordset.Recordcount
    that would be the total of all the books in the recordset

    what you really need is something like a sql query to insert the value into all the records where bookname = hi, using a count query of the same to get the number to put into all the records
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    New Member
    Join Date
    Dec 2007
    Posts
    10

    Re: how to i increase the (column,row) of a specfic value thanks!!

    Quote Originally Posted by westconn1
    that would be the total of all the books in the recordset

    what you really need is something like a sql query to insert the value into all the records where bookname = hi, using a count query of the same to get the number to put into all the records
    could you help me with the codes thanks =)

  6. #6

    Thread Starter
    New Member
    Join Date
    Dec 2007
    Posts
    10

    Re: how to i increase the (column,row) of a specfic value thanks!!

    any one?

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: how to i increase the (column,row) of a specfic value thanks!!

    you can try like this, but check for correct results
    vb Code:
    1. Dim rcnt As Recordset, lcnt As Long
    2. Set rcnt = Data1.Database.OpenRecordset("Select Count(*) from Table1 Where BOOKNAME='" & tempBook & "'")
    3. lngcnt = rcnt(0)
    4. rcnt.Close
    5. Set rcnt = Nothing
    6. Data1.Database.Execute "update table1 set avalibility =" & lngcnt & " where BOOKNAME = '" & tempbook & "'"
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

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