G
Guest
As contributor “rkc†once pointed out to me, if I am to borrow code that someone else has written then I should at least understand what it does. Copying, pasting, and modifying text so that the code works on a current db is one thing – really understanding how the code works is something else again. I am trying to get educated by experience, trial and error, books, and this newsgroup. I’m bugged by not understanding this code and I don’t have my books with me right now and I’m not sure that I even have the right books for these questions, so I’m hoping that I can get some help here
I apologize in advance for the lengthy post and the ‘twenty questions’ format
If anyone has the time, I’d appreciate some explanations of the “how and why†of the following (commonly used) VBA code. I have looked up some of the words in the help files, but I’m still foggy on understanding the details of it. I’m adding what I think I understand and my questions after the code
Private Sub cboMyCombo_AfterUpdat
Dim rs As Objec
Set rs = Me.Recordset.Clon
rs.FindFirst “[MySubjectID] = “ & Str(Nz(Me![cboMyCombo], 0)
If Not rs.EOF Then Me.Bookmark = rs.Bookmar
End Su
My understanding is that in order for the form to display a particular record (selected by the combo box), Access must know where that record is currently located in the record source (a new ‘bookmark’ is created everytime the form is opened). The first two lines of the code create a new (virtual or temporary?) object (named ‘rs’) that is an exact duplicate of the forms record source. The third line locates the first record (and bookmark) that matches the value in the combo box. The last line sets the forms bookmark to match the bookmark of the virtual recordset (but only if the ‘findfirst’ action/method did not reach the end of the file)
I’m most confused about and would appreciate an explanation of
“[MySubjectID] = “ & Str(Nz(Me![cboMyCombo], 0))â€.
I see that the value of the combo is converted into a string and then the string is used for comparing to the field values. My questions
1. Why does it need to be a string? The bound column of the combo and the field are both formated as number/long integer. Couldn't value be matched to value
2. Why are the quotation marks enclosing the field name and the operator?
3. Why is the ampersand needed and/or what is its function here
4. Why the ‘Nz’?
5. Why a comma and then the zero? Is the zero indicating which column number of the combo's record source to search
6. Why is there a bang (!) between ‘Me’ and ‘[cboMyCombo]’ as opposed to a dot (.
7. I’ve read where it is sometimes useful to read VBA code right-to-left to understand it better, but how is one to know WHEN you should do so? (The Excel formulas I’ve worked with are easy to understand in comparison to VBA.
8. Feel free to offer any other information
TI
Rick..
I apologize in advance for the lengthy post and the ‘twenty questions’ format
If anyone has the time, I’d appreciate some explanations of the “how and why†of the following (commonly used) VBA code. I have looked up some of the words in the help files, but I’m still foggy on understanding the details of it. I’m adding what I think I understand and my questions after the code
Private Sub cboMyCombo_AfterUpdat
Dim rs As Objec
Set rs = Me.Recordset.Clon
rs.FindFirst “[MySubjectID] = “ & Str(Nz(Me![cboMyCombo], 0)
If Not rs.EOF Then Me.Bookmark = rs.Bookmar
End Su
My understanding is that in order for the form to display a particular record (selected by the combo box), Access must know where that record is currently located in the record source (a new ‘bookmark’ is created everytime the form is opened). The first two lines of the code create a new (virtual or temporary?) object (named ‘rs’) that is an exact duplicate of the forms record source. The third line locates the first record (and bookmark) that matches the value in the combo box. The last line sets the forms bookmark to match the bookmark of the virtual recordset (but only if the ‘findfirst’ action/method did not reach the end of the file)
I’m most confused about and would appreciate an explanation of
“[MySubjectID] = “ & Str(Nz(Me![cboMyCombo], 0))â€.
I see that the value of the combo is converted into a string and then the string is used for comparing to the field values. My questions
1. Why does it need to be a string? The bound column of the combo and the field are both formated as number/long integer. Couldn't value be matched to value
2. Why are the quotation marks enclosing the field name and the operator?
3. Why is the ampersand needed and/or what is its function here
4. Why the ‘Nz’?
5. Why a comma and then the zero? Is the zero indicating which column number of the combo's record source to search
6. Why is there a bang (!) between ‘Me’ and ‘[cboMyCombo]’ as opposed to a dot (.
7. I’ve read where it is sometimes useful to read VBA code right-to-left to understand it better, but how is one to know WHEN you should do so? (The Excel formulas I’ve worked with are easy to understand in comparison to VBA.
8. Feel free to offer any other information
TI
Rick..