Results 1 to 31 of 31

Thread: Connection Object Question [Resolved]

  1. #1

    Thread Starter
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Connection Object Question [Resolved]

    Hi! I have this two table namely Books and BorrowedBooks. The books table has field named as "Available" which has Yes/No data type. What i want to achieve is that when I issue a certain book, I would like the the "Available" field which is by default is checked [the check box] would be unchecked. Right now i have this code: I dunno know if what im doing actually is correct.

    VB Code:
    1. Private Sub cmdIssueBook1_Click()
    2. Dim sSQL1 As String
    3. Dim sSQL2 As String
    4.  
    5. sSQL1 = "INSERT INTO BorrowedBooks (IDNO,Title,AccNum,DateBorrowed,DateDue) VALUES" & _
    6.     "('" & lblStudIDDisp.Caption & "','" & lblBook1Title.Caption & _
    7.      "','" & lblAccNum1.Caption & "','" & lblDateBorrowedDisp.Caption & _
    8.      "','" & lblDateDueDisp.Caption & "')"
    9.     MyConn.Execute sSQL1, , adCmdText + adExecuteNoRecords
    10.        
    11.     MyConn.Execute sSQL1, "UPDATE books SET Available = TRUE"
    12.        
    13. If MyRs6.State = 1 Then MyRs6.Close
    14. sSQL2 = "SELECT LName,FName,MI from borrowers where LName= '" & lblStudLNameDisp.Caption & "'AND FName='" & lblStudFName.Caption & "' and MI='" & lblStudMIDisp.Caption & "'"
    15. MyRs6.Open sSQL2, MyConn, adOpenKeyset, adLockOptimistic
    16.  
    17. MsgBox "Book has been recorded to the account of " & lblStudFNameDisp.Caption & " " & lblStudMIDisp.Caption & " " & lblStudLNameDisp.Caption & "."
    18. End Sub

    my first time to use .execute
    Last edited by Simply Me; Mar 28th, 2005 at 12:19 AM.
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Connection Object Question

    First question is "Does it work?" I would think that you'd have to tell it which record in the Books table that you want to update. Other than that, it looks correct to me,but it is awfully late around here

  3. #3

    Thread Starter
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Re: Connection Object Question

    Quote Originally Posted by dglienna
    First question is "Does it work?" I would think that you'd have to tell it which record in the Books table that you want to update. Other than that, it looks correct to me,but it is awfully late around here
    it does record the book the borrowedbooks (twice though) but not unchecked the book in the books table.

    How do i specify which book is it? ahhh, I will use the primary of that book. but how?
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Connection Object Question

    Quote Originally Posted by Simply Me
    it does record the book the borrowedbooks (twice though) but not unchecked the book in the books table.

    How do i specify which book is it? ahhh, I will use the primary of that book. but how?
    Don't know why it does it twice.

    something like this?

    "UPDATE books SET Available = TRUE WHERE IDNO = " & text1.text

  5. #5

    Thread Starter
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Re: Connection Object Question

    Quote Originally Posted by dglienna
    Don't know why it does it twice.

    something like this?

    "UPDATE books SET Available = TRUE WHERE IDNO = " & text1.text
    it is still not unchecking my yes/no field in my books table.

    btw im using access
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

  6. #6
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808

    Re: Connection Object Question

    Try this:

    VB Code:
    1. MyConn.Execute sSQL1, "UPDATE books SET Available = [B]1[/B] " & _
    2.   & "WHERE IDNO = " & lblStudIDDisp.Caption
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  7. #7
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808

    Re: Connection Object Question

    One question, though.... if your book is borrowed, shouldn't the Available field change to 0??
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  8. #8

    Thread Starter
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Re: Connection Object Question

    Quote Originally Posted by Mc Brain
    One question, though.... if your book is borrowed, shouldn't the Available field change to 0??
    My Available field is uses the Yes/No (by default is checked) data type in access. so if it borrowed then will be unchecked.

    ooopppsss my code is =true. thats why im not getting anything. I'll try it again.

    I tried using 0 and still not giving me correct result
    Last edited by Simply Me; Mar 27th, 2005 at 12:48 AM.
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

  9. #9

    Thread Starter
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Re: Connection Object Question

    anyone here please?
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

  10. #10
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Connection Object Question

    Try -1, False, 0, 1, True, "1", "-1", "0" one of them should work
    (I was going to say use false last night)

  11. #11

    Thread Starter
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Re: Connection Object Question

    Quote Originally Posted by dglienna
    Try -1, False, 0, 1, True, "1", "-1", "0" one of them should work
    (I was going to say use false last night)
    tried this double qoute and the others and it is error. tried single Qoute, still not unchecking.
    VB Code:
    1. MyConn.Execute sSQL1, "UPDATE books SET Available = "0" WHERE AccNum = '" & Val(lblAccNum1.Caption) & "'"
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

  12. #12
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Connection Object Question

    it's probably the other section. the acc num, try to see if the where part is right.

  13. #13

    Thread Starter
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Re: Connection Object Question

    Quote Originally Posted by dglienna
    it's probably the other section. the acc num, try to see if the where part is right.
    Even though i remove this:

    WHERE AccNum = '" & Val(lblAccNum1.Caption) & "'"

    still not unchecking the availabe field.
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

  14. #14
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Connection Object Question

    Try putting a valid number in instead of the field.
    then change the values. I googled and found this:

    VB Code:
    1. UPDATE Person
    2. SET Address = 'Stien 12', City = 'Stavanger'
    3. WHERE LastName = 'Rasmussen'

  15. #15
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Connection Object Question

    Here is the sql code out of access with a yes/no field and the correct field info.
    It unchecks the checked checkbox.

    VB Code:
    1. UPDATE FICHAS
    2. SET FICHAS.[check] = '0'
    3. WHERE (((FICHAS.Factores)='1'));

    an old db that i had on my system. aded the check field, changed factores to 1 and then ran it. it changed check to unchecked (0)

  16. #16

    Thread Starter
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Re: Connection Object Question

    Quote Originally Posted by dglienna
    Here is the sql code out of access with a yes/no field and the correct field info.
    It unchecks the checked checkbox.

    VB Code:
    1. UPDATE FICHAS
    2. SET FICHAS.[check] = '0'
    3. WHERE (((FICHAS.Factores)='1'));

    an old db that i had on my system. aded the check field, changed factores to 1 and then ran it. it changed check to unchecked (0)
    can you explain further please?
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

  17. #17
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Connection Object Question

    I added the field check and then changed a record in the db, and made the factores field equal to 1. I then checked the checkbox.

    I then messed around making a query until I had one that did what I wanted.
    I then posted the sql for you. that sql unchecks the box where factores=1

  18. #18
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Connection Object Question

    VB Code:
    1. MyConn.Execute sSQL1, "UPDATE books SET books.Available = '0' WHERE books.AccNum = '" & Val(lblAccNum1.Caption) & "'"

    Maybe?

  19. #19

    Thread Starter
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Re: Connection Object Question

    Quote Originally Posted by dglienna
    VB Code:
    1. MyConn.Execute sSQL1, "UPDATE books SET books.Available = '0' WHERE books.AccNum = '" & Val(lblAccNum1.Caption) & "'"

    Maybe?
    Tried that one too.
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

  20. #20
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Connection Object Question

    Get a valid book number (Ill subtitute 999 for this example, and try this. if the book isn't a numeric value you would have a problem

    VB Code:
    1. MyConn.Execute sSQL1, "UPDATE books SET books.Available = '0' WHERE books.AccNum = '999'"

  21. #21

    Thread Starter
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Re: Connection Object Question

    Quote Originally Posted by dglienna
    Get a valid book number (Ill subtitute 999 for this example, and try this. if the book isn't a numeric value you would have a problem

    VB Code:
    1. MyConn.Execute sSQL1, "UPDATE books SET books.Available = '0' WHERE books.AccNum = '999'"
    not working still....
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

  22. #22
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Connection Object Question

    Show your code with the valid book number. Are you sure the query is even executing? Did you step through it using F8? It worked on my machine.
    Is there a problem with your connection string, the .Execute method, or something else not related to the Update?

  23. #23

    Thread Starter
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Re: Connection Object Question

    Quote Originally Posted by dglienna
    Show your code with the valid book number. Are you sure the query is even executing? Did you step through it using F8? It worked on my machine.
    Is there a problem with your connection string, the .Execute method, or something else not related to the Update?
    Dim sSQL1 As String
    Dim sSQL2 As String
    Dim sql As String

    sSQL1 = "INSERT INTO BorrowedBooks (IDNO,Title,AccNum,DateBorrowed,DateDue) VALUES" & _
    "('" & lblStudIDDisp.Caption & "','" & lblBook1Title.Caption & _
    "','" & lblAccNum1.Caption & "','" & lblDateBorrowedDisp.Caption & _
    "','" & lblDateDueDisp.Caption & "')"
    MyConn.Execute sSQL1, , adCmdText + adExecuteNoRecords

    MyConn.Execute sSQL1, "UPDATE books SET Available = '0' WHERE AccNum = 100000
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

  24. #24
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808

    Re: Connection Object Question

    Are you sure you don't have an On Error Resume Next somewhere? Maybe you have one, the code is raising an error... and going on with the next line.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  25. #25
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Connection Object Question

    Maybe because you left off the quotes?

    VB Code:
    1. MyConn.Execute sSQL1, "UPDATE books SET books.Available = '0' WHERE books.AccNum = '100000'"

    that's how outlook does it. after it works, you can remove things.
    paste this in and try it.

  26. #26

    Thread Starter
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Re: Connection Object Question

    Quote Originally Posted by Mc Brain
    Are you sure you don't have an On Error Resume Next somewhere? Maybe you have one, the code is raising an error... and going on with the next line.
    no i dont have any
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

  27. #27
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Connection Object Question

    Did you try my last suggestion?

  28. #28

    Thread Starter
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Re: Connection Object Question

    thanks for your replies buddies your replies helped me alot and special thanks to erickwidya.

    this is my final code and it is working now.

    VB Code:
    1. sSQL1 = "INSERT INTO BorrowedBooks (IDNO,Title,AccNum,DateBorrowed,DateDue) VALUES" & _
    2.     "('" & lblStudIDDisp.Caption & "','" & lblBook1Title.Caption & _
    3.      "','" & lblAccNum1.Caption & "','" & lblDateBorrowedDisp.Caption & _
    4.      "','" & lblDateDueDisp.Caption & "')"
    5.    
    6.     MyConn.Execute sSQL1, , adCmdText + adExecuteNoRecords
    7.     sSQL = "UPDATE [books] SET [Available] = 0 WHERE AccNum = '" & Val(lblAccNum1.Caption) & "'"
    8.     MyConn.Execute sSQL
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

  29. #29
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Connection Object Question

    Quote Originally Posted by Simply Me
    thanks for your replies buddies your replies helped me alot and special thanks to erickwidya.

    this is my final code and it is working now.

    What did he say?
    Glad it's working, but as I said, I ran an update that worked exactly the way that I said to do it.

  30. #30
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808

    Re: Connection Object Question [Resolved]

    I can't believe it!! The only difference are the brakets!! Are you telling me that 'Available' is a reserved word for SQL and/or Access???
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  31. #31
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Connection Object Question [Resolved]

    I thought about that, but decided prolly not. He didn't say what it was.

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