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, 10:30 AM
Authorized User
 
Join Date: Aug 2006
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help Debug

Hi everyone,
  I have a button which keeps throwing errors at me. The code is:
Code:
Private Sub ISBN_Exit(Cancel As Integer)
Set db = CurrentDb()
Set rst = db.OpenRecordset("tbl_Books", dbOpenDynaset)

'all information in here where "Order#" is a column in your table
strISBN = [ISBN]
rst.FindFirst (strISBN)
[Book_Title] = rst("Book_Title")
[Publisher] = rst("Publisher")
[Copyright] = rst("Copyright")
[Edition] = rst("Edition")
[Author] = rst("Author")
[Book_Type] = rst("Book_Type")
[Trial_Software] = rst("Trial_Software")
[Comments] = rst("Comments")
rst.Update

rst.Close

End Sub
The error is invalid argument on the following line:
Code:
rst.FindFirst (strISBN)
Any help would be great.

Thanks in advance,
Arholly

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

What does [ISBN] refer to? Perhaps you need to be more specific, like:

strISBN = [Forms]![frmName].[ISBN]

or

strISBN = Me.ISBN





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

Alternatively, if you are not pulling any records, then FindFirst would throw an error too. Are you sure there are records available when you pull the recordset?

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

Okay, I tried both of your suggestions and both keep throwing the same error. And I'm copying an ISBN directly from the table to make sure I'm getting the correct ISBN, so I'm not sure what would be the problem.

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

Try this then:

rst.FindFirst strISBN


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

Still an invalid argument. If you can think of a better way to do this, I'm more than willing to listen.

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

Can you do this:

Dim strISBN, sSQL As String
strISBN = Me.ISBN
sSQL = "tbl_Books WHERE [ISBN] = '" & strISBN & "'"

...
Set rst = db.OpenRecordset(sSQL, dbOpenDynaset)

Then no need to use FindFirst statement.


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

Or you may need to do this:
sSQL = "SELECT * FROM tbl_Books WHERE [ISBN] = '" & strISBN & "'"

I don't use DAO since I mostly do Access/SQL.


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

Okay, when I try that the following error:
"The Microsoft Jet database enging cannot find the input table or query 'tbl_Books WHERE [ISBN] ='0321321847''.

Did I put the code in the wrong order?
Set db = CurrentDb()
Dim strISBN, sSQL As String
strISBN = Me.ISBN
sSQL = "tbl_Books WHERE [ISBN] = '" & strISBN & "'"
Set rst = db.OpenRecordset(sSQL, dbOpenDynaset)

'all information in here where "Order#" is a column in your table
'strISBN = [Forms]![frm_Edit_Book].[ISBN]
'rst.FindFirst strISBN
[Book_Title] = rst("Book_Title")

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

The second bit of code worked, but then threw an error saying:
Update or CancelUpdate without AddNew or Edit, which I then fixed by dumping the rst.Update. Thanks so much for your help.

Thanks again,
Arholly






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.