collection question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

On an afterUpdate event on a form control, the user has selected which
appointment information they wish to view. THe form is unbound and I
programmatically load the form from the selection made.

I have the following code initiating this sub:

mparts_frmSurgProc.brSave

Set mctrls_frmSurgProc = Nothing
Set mparts_frmSurgProc = Nothing

mparts_frmSurgProc and mctrls_frmSurgProc are collections. As the user
clicks different appointments, his edits are saved and the collections set to
nothing prior to loading the new appointment info from his selection. This is
a problem if the user just opened the form and this is the first selection
(nothing to save). How do I
determine if mparts_frmSurgProc is empty so I can skip the first line when
needed?

Thanks

(This is another developer's code, hence I don't know that much about
collections and the handling thereof)
 
Collections have a Count property that will tell you how many items are in
the collection.
 
Hi, Sam.
How do I
determine if mparts_frmSurgProc is empty so I can skip the first line when
needed?

As you may have already discovered, using the IsEmpty( ) function doesn't
tell you if the collection is empty or not, because this function is supposed
to be used to determine whether a Variant was not initialized or was
explicitly set to Empty. Instead, the collection's Count property can be
checked to determine whether there are any items in the collection. For
example:

' * * * * Start Code * * * *

Public Sub testCollections()

On Error GoTo ErrHandler

Dim cStrings As Collection

If (IsEmpty(cStrings)) Then
MsgBox "It's not been initialized."
Else
MsgBox "It's been initialized."
End If

Set cStrings = New Collection

If (cStrings.Count = 0) Then
MsgBox "Collection of strings is empty."
Else
MsgBox "Collection of strings is " & cStrings.Count
End If

cStrings.Add "First item"
cStrings.Add "Second item"

If (cStrings.Count = 0) Then
MsgBox "Collection of strings is now empty."
Else
MsgBox "Collection of strings is now " & cStrings.Count
End If

Set cStrings = Nothing

Exit Sub

ErrHandler:

MsgBox "Error in testCollections( )." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.Description
Err.Clear

End Sub

' * * * * End Code * * * *

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)
Beware to those who use munged addresses: known newsgroup E-mail harvesters
for spammers are (e-mail address removed) and (e-mail address removed)

- - -
When you see correct answers to your question posted in Microsoft's Online
Community, please sign in to the Community and mark these posts as "Answers,"
so that all may benefit by filtering on "Answered questions" and quickly
finding the right answers to similar questions. Remember that questions
answered the quickest are often from those who have a history of rewarding
the contributors who have taken the time to answer questions correctly.
 
Back
Top