Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need explaination for this procedure

Status
Not open for further replies.

longmatch

Programmer
Nov 1, 2001
406
I am learning Access VBA now. I do not know the meaning of this procedure. Please give me some explaination. Thanks in advance.

haijun

Private Sub cboFind_AfterUpdate()
Me.RecordsetClone.Findfirst "CustomerID = """ & Me!cboFind & """"
Me.Bookmark = Me.RecordsetClone.Bookmark
End Sub

Private Sub cboFirst_AfterUpdate()
cboFind.Requery
cboFind.SetFocus
End Sub
 
The first sub searches the recordset of your form for a record who's customer ID matches that of the Find combo box and then moves the form's recordset pointer to that record. In other words it displays that record.

The second updates the 'list' of customers in the find combo after the 'First' combo is updated and moves the insertion point to the Find combo box. I can't help you with what the 'First' combo is for.

"The Key, The Whole Key, and Nothing But The Key, So Help Me Codd!"
 
There are two procedures here. The first one is linked to a combo box that displays a list of customer IDs. Basically what it does is find a record in the underlying form's record source field called "Customer ID" that matches the CUSTOMER ID selected in the combo box.

It then positions to that record and displays it on the form, using the RecordsetClone guy and the BOOKMARK property.

This is a "find a record on my form" combo-box wizard-generated codelet.


The second procedure re-runs the query that is the basis for the "CBOFIND" combo box, and then puts the focus there (to the combo box).

They both 'run' AFTER a choice is made from the combo-box's drop down list. Hence, the "After Update" event....





Jim Hare
"Remember, you're unique - just like everyone else"
 
Thank you for your help. I just still can not figure out why there are 3 set of "" around Me!cboFind and why & is used here. What is the logic here? I need your further help.


Haijun
 
Whenever you pass a string value to another string to be used as a criteria, you need to "wrap" it in quotes..

There's a difference (slight, though it may be) between the single quote and the double quote, so we use it to "embed" a quoted string within another quoted string:

"CustomerID = [red]'[/red]10[red]'[/red] "

See the need? The trouble is, sometimes our monitors or fonts don't accurately show the difference between "'" and """ or """"...








Jim Hare
"Remember, you're unique - just like everyone else"
 
( wish you could EDIT your posts here instead of having to add another one..)

What throws us off is the use in your example of DOUBLE quotes all around.

THIS IS A STRING & " " " comes out as

THIS IS A STRING "

where as FOUR QUOTES """" leaves two:

forms!cboCustID & " " " " resolves to

123" "

It would have been much simpler if your example used SINGLE quotes around the customer id reference:

"CustomerID = ' " & forms!cboID & " ' " ..

Now I'm confused... [smile]

Jim Hare
"Remember, you're unique - just like everyone else"
 
Jim,

I don't know if when you say "Now I'm confused..." you're being facecious, but I'll explain.

When Access sees the first quote (an 'open quote') it looks for the next one and considers it a 'close quote'. This causes some troubles when you need to embed a literal quote. You can get around this by embedding a single quote as in your example. Alternatively you can embed two double quotes which Access interprets as a single double quote as in haijun's example. Either one works.

For the record, I find embedded single quotes MUCH easier to code, read and debug.

Your final example of "CustomerID = ' " & forms!cboID & " ' " is definately the way to go although like I said, either one will work.
"The Key, The Whole Key, and Nothing But The Key, So Help Me Codd!"
 
This code is really difficult to figure out. I try to analyze it through this way, but I still can not understand.
"CustomerID = """ & Me!cboFind & """"
The first set of "" signals that
custmerID =""" & Me!cboFind & """ as a string
The second set of "" around "" & Me!cboFind & "" means a string will be assigned to CustomerID.
But why do we need other two set of "" along with a pair of &. I am lost here.

Still need clarification.

Haijun
 
The .FindFirst method takes a string parameter in the form of a SQL WHERE clause. A string is always enclosed in quotes. An example might be:

WHERE CustomerID = 'Smith'

(Note the open and close quotes around Smith, more just below)

(Also, on't get hung up on the WHERE, it is not passed as part of the string, I'm only including it here to hopefully make this make more sense)

Your example is building this SQL string 'on the fly' from some text, "CustomerID =", and the value of cboFind. To do that we concatenate the string "CustomerID ='" (note the embedding open quote to go around the value from cboFind) with the value from cboFind using & and tack on a trailing quote (the close quote on the other end of the value from cboFind) with another &.

Hope that helps.

"The Key, The Whole Key, and Nothing But The Key, So Help Me Codd!"
 
I was being facet..facitic..silly.

Quoted strings are a PITA for many new users, and I feel his pain, as SlickWillie used to say.

I've even resorted to using CHR$(34) instead of a quote, or a constant such as vbQuote that I assign..

MyString = "THIS STUFF IS A " & VBQUOTE & "PAIN" & VBQUOTE & "IN THE BUTT" to get

THIS STUFF IS A 'PAIN' IN THE BUTT
Jim Hare
"Remember, you're unique - just like everyone else"
Feel free to visit another free Access forum:
or my site,
 
I guess I did misspell that :) "The Key, The Whole Key, and Nothing But The Key, So Help Me Codd!"
 
Thank everybody who gave me help on this question. Right now I knew that only three pair of "" needed in this code. I just tried it in my database. It works fine. I am still wondering the role of a pair of & in this code. When I deleted both of & from this code, it can not compile. Why? I do not know. It does not look like that & is used as concatenation, because one is enough. Why two of them are used in this. Need more help. Thank you.

Haijun
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top