Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access 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
  #1 (permalink)  
Old March 10th, 2006, 05:10 PM
Registered User
 
Join Date: Mar 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default VBA - clueless

I have two questions in regards to the below example.

1. On the second to last line it says 'rs.CustName'. Now where does rs come from and what does it mean? Is it a misspelling of 'rst'??
2. I assume that CustName is a name of one of the fields in the table. I get an error message when I try to separate the recordset and a field with a dot (rst.CustomerId) but it works if I use an exclamation mark (rst!CustomerId). Why is this? I cant see what i am doing different that what they are doing in the book.

Help will be very appreciated!

Example:

'Open the database that contains the table that is linked
Set dbs = OpenDatabase(strMyExternalDatabase)
'Open a table-type recordset against the external table
Set rst = dbs.OpenRecordset("tblCustomers", dbOpenTable)
'Specify which index to search on
rst.Index = "CustomerNo"
'Specify the criteria
rst.Seek "=", 123
'Check the result
If rst.NoMatch Then
MsgBox "Record not found."
Else
MsgBox "Customer name: " & rs.CustName
End If

  #2 (permalink)  
Old March 10th, 2006, 08:17 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Hello,

rs.CustName is errata on both counts. The line should read:

Code:
MsgBox "Customer name: " & rst!CustName
Bang (!) notation means that the identifier that follows refers to a member of a collection. CustName is a member of the Recordset's Fields collection. rst!CustName works because the Fields collection is the default property of a Recordset object (the Fields collection is implied).

Dot (.) notation means that the identifier that follows it refers to a property or method of the object. So since the Fields collection is a property of the Recordset object, you could also use:

Code:
rst.Fields("CustName")
HTH,

Bob



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA help davidbrooks Visual Basic 2008 Essentials 2 March 26th, 2008 07:25 PM
Code works in Excel VBA but not Access VBA fossx Access VBA 2 May 21st, 2007 08:00 AM
A little clueless, need some pointers bmg181 ASP.NET 2.0 Basics 3 December 23rd, 2005 01:21 PM
New to VBA. Please help me. rupen Access VBA 1 May 27th, 2005 07:54 AM
Excel VBA to SQL & back to VBA edesousa Excel VBA 1 June 1st, 2004 02:39 AM





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