|
-
Mar 26th, 2005, 04:00 AM
#1
Thread Starter
PowerPoster
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:
Private Sub cmdIssueBook1_Click()
Dim sSQL1 As String
Dim sSQL2 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 = TRUE"
If MyRs6.State = 1 Then MyRs6.Close
sSQL2 = "SELECT LName,FName,MI from borrowers where LName= '" & lblStudLNameDisp.Caption & "'AND FName='" & lblStudFName.Caption & "' and MI='" & lblStudMIDisp.Caption & "'"
MyRs6.Open sSQL2, MyConn, adOpenKeyset, adLockOptimistic
MsgBox "Book has been recorded to the account of " & lblStudFNameDisp.Caption & " " & lblStudMIDisp.Caption & " " & lblStudLNameDisp.Caption & "."
End Sub
my first time to use .execute
Last edited by Simply Me; Mar 28th, 2005 at 12:19 AM.
-
Mar 26th, 2005, 04:19 AM
#2
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
-
Mar 26th, 2005, 04:26 AM
#3
Thread Starter
PowerPoster
Re: Connection Object Question
 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?
-
Mar 26th, 2005, 04:35 AM
#4
Re: Connection Object Question
 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
-
Mar 26th, 2005, 04:41 AM
#5
Thread Starter
PowerPoster
Re: Connection Object Question
 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
-
Mar 26th, 2005, 07:46 AM
#6
Need-a-life Member
Re: Connection Object Question
Try this:
VB Code:
MyConn.Execute sSQL1, "UPDATE books SET Available = [B]1[/B] " & _
& "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.
-
Mar 26th, 2005, 07:48 AM
#7
-
Mar 26th, 2005, 07:37 PM
#8
Thread Starter
PowerPoster
Re: Connection Object Question
 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.
-
Mar 27th, 2005, 01:00 AM
#9
Thread Starter
PowerPoster
Re: Connection Object Question
-
Mar 27th, 2005, 01:02 AM
#10
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)
-
Mar 27th, 2005, 01:16 AM
#11
Thread Starter
PowerPoster
Re: Connection Object Question
 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:
MyConn.Execute sSQL1, "UPDATE books SET Available = "0" WHERE AccNum = '" & Val(lblAccNum1.Caption) & "'"
-
Mar 27th, 2005, 01:26 AM
#12
Re: Connection Object Question
it's probably the other section. the acc num, try to see if the where part is right.
-
Mar 27th, 2005, 01:33 AM
#13
Thread Starter
PowerPoster
Re: Connection Object Question
 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.
-
Mar 27th, 2005, 01:42 AM
#14
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:
UPDATE Person
SET Address = 'Stien 12', City = 'Stavanger'
WHERE LastName = 'Rasmussen'
-
Mar 27th, 2005, 02:05 AM
#15
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:
UPDATE FICHAS
SET FICHAS.[check] = '0'
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)
-
Mar 27th, 2005, 09:26 PM
#16
Thread Starter
PowerPoster
Re: Connection Object Question
 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:
UPDATE FICHAS
SET FICHAS.[check] = '0'
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?
-
Mar 27th, 2005, 09:35 PM
#17
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
-
Mar 27th, 2005, 09:38 PM
#18
Re: Connection Object Question
VB Code:
MyConn.Execute sSQL1, "UPDATE books SET books.Available = '0' WHERE books.AccNum = '" & Val(lblAccNum1.Caption) & "'"
Maybe?
-
Mar 27th, 2005, 09:41 PM
#19
Thread Starter
PowerPoster
Re: Connection Object Question
 Originally Posted by dglienna
VB Code:
MyConn.Execute sSQL1, "UPDATE books SET books.Available = '0' WHERE books.AccNum = '" & Val(lblAccNum1.Caption) & "'"
Maybe?
Tried that one too.
-
Mar 27th, 2005, 10:26 PM
#20
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:
MyConn.Execute sSQL1, "UPDATE books SET books.Available = '0' WHERE books.AccNum = '999'"
-
Mar 27th, 2005, 10:35 PM
#21
Thread Starter
PowerPoster
Re: Connection Object Question
 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:
MyConn.Execute sSQL1, "UPDATE books SET books.Available = '0' WHERE books.AccNum = '999'"
not working still....
-
Mar 27th, 2005, 10:46 PM
#22
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?
-
Mar 27th, 2005, 10:57 PM
#23
Thread Starter
PowerPoster
Re: Connection Object Question
 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
-
Mar 27th, 2005, 11:01 PM
#24
-
Mar 27th, 2005, 11:23 PM
#25
Re: Connection Object Question
Maybe because you left off the quotes?
VB Code:
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.
-
Mar 27th, 2005, 11:34 PM
#26
Thread Starter
PowerPoster
Re: Connection Object Question
 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
-
Mar 27th, 2005, 11:37 PM
#27
Re: Connection Object Question
Did you try my last suggestion?
-
Mar 28th, 2005, 12:17 AM
#28
Thread Starter
PowerPoster
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:
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
sSQL = "UPDATE [books] SET [Available] = 0 WHERE AccNum = '" & Val(lblAccNum1.Caption) & "'"
MyConn.Execute sSQL
-
Mar 28th, 2005, 12:24 AM
#29
Re: Connection Object Question
 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.
-
Mar 28th, 2005, 04:47 AM
#30
Need-a-life Member
-
Mar 28th, 2005, 04:52 AM
#31
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|