Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 18th, 2006, 11:13 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

In fact, here is how I would do this in ADO:

Dim rst As ADODB.Recordset
Dim sSQL, sISBN as String

If IsNull(Me.ISBN) Or Me.ISBN = "" Then
   MsgBox "Please enter an ISBN", vbCritical
Else
   sISBN = Me.ISBN
End If

sSQL = "SELECT * FROM tbl_Books WHERE [ISBN] = '" & sISBN & "'"

Set rst = New ADODB.Recordset
rst.Open sSQL, CurrentProject.Connecton, adOpenDynamic, adLockOptimistic

rst("Book_Title") = Me.Book_Title
rst("Publisher") = Me.Publisher
rst("Copyright") = Me.Copyright
rst("Edition") = Me.Edition
rst("Author") = Me.Author
rst("Book_Type") = Me.Book_Type
rst("Trial_Software") = Me.Trial_Software
rst("Comments") = Me.Comments
rst.Update
rst.Close

HTH


mmcdonal
 
Old December 18th, 2006, 11:14 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

I guess the upshot is that ISBN's are unique, so they are probably your PK, and as such are indexed with no dupes. In that case, FindFirst is superfluous if you parameterize the recordset.



mmcdonal
 
Old December 18th, 2006, 11:19 AM
Authorized User
 
Join Date: Aug 2006
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I like that code, but it keeps throwing an error message for the MsgBox portion of the code. So, I fixed that but then started getting this error for this line of code:
Code:
rst.Open sSQL, CurrentProject.Connecton, adOpenDynamic, adLockOptimistic
The message said "Object doesn't support this property or method."


 
Old December 18th, 2006, 11:36 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Type the code in by hand rather than pasting, and see what autocomplete options you get. Then use the autocomplete options.

mmcdonal
 
Old December 18th, 2006, 11:58 AM
Authorized User
 
Join Date: Aug 2006
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Okay, I did the code by hand but now it does not look up anything. Any thoughts?

 
Old December 18th, 2006, 12:35 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

When you say it does nothing now, how far does it get?
I mean, you want to use an ISBN (unique identifier) on your form, use it to pull its record from the proper table, then update the record in the table based on data recently typed in the form.
So you take the ISBN in the variable (it is a string or number in the database?), add it to the sSQL string, and pull the record.

Are you saying it is not pulling any record? Or it is throwing an error?


mmcdonal
 
Old December 18th, 2006, 12:37 PM
Authorized User
 
Join Date: Aug 2006
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry, I was not clear. It is not pulling any records now. When I switched out the code for the code below, it stopped pulling any records. My bad on the bad communication.

 
Old December 18th, 2006, 12:47 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

There may be parameter issues with type mismatches or something. Can you either enter a parameter you know is there, or remove the parameter, and the update, and have it give you the recordcount boolean, like:

Dim bCount as Boolean

sSQL = "SELECT * FROM tbl_Books"

rst.Open etc.

bCount = rst.Recordcount

Msgbox bCount

See if this doesn't come up with a 0





mmcdonal
 
Old December 18th, 2006, 12:50 PM
Authorized User
 
Join Date: Aug 2006
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Okay, here is something else I discovered. When it is looking up the record, it is blanking all the values out. So, it looks like it is updating all the fields with the blanks instead of just looking up the information.

I checked this by actually looking in the table itself to make sure everything is going correct and low and behold.

 
Old December 18th, 2006, 01:52 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

This is a problem with taking values at runtime. I would suggest taking the form field values in seperate variables first, then open the recordset, then paste the values from the variables, like:

Dim sAuthor As String

sAuthor = Me.Author

rst("Author") = sAuthor

That is how I usually do it.



mmcdonal





Similar Threads
Thread Thread Starter Forum Replies Last Post
Debug Programe u.muslimboy BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 3 October 5th, 2006 02:22 PM
Debug.Assert BrianWren VB.NET 2002/2003 Basics 1 March 7th, 2005 05:33 PM
C++ Debug Problem junebug C++ Programming 1 February 11th, 2005 01:41 PM
Can't debug sithlrd General .NET 9 July 28th, 2004 05:00 PM
Can't Debug shmacgregor General .NET 6 March 1st, 2004 05:10 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.