Ptoblem with Dictionary Code

  • Thread starter Thread starter John Morgan
  • Start date Start date
J

John Morgan

I am having a problem trying to use a Dictionary object in Access VBA.
I assume that hte object is valid for Access VBA as it happily accepts
new keys and items.
However the following code will not work even though the key and item
value is added successfully a few lines above and is tested
successfully there immediately after being added.

The file is and Access adp file.

The code is:

Dim sKey, sName As String
sKey = "VicePresident"
If officeCandidateCountDictionary.exists(sKey) Then
MsgBox "Exists true for " & sKey
'////////// the MsgBox opens up as expected presumably confirming the
key exists
sName = CStr((officeCandidateCountDictionary.Item(sKey))) '//////
this statement fails
MsgBox "The value is " & sName
Else
MsgBox "The key " & sKey & " does not exist"
End If

You will see from the remarks in the code that the initial test
indicates that the key exists but then the following line fails.
suppose its something simple but if anyone can help me then I would be
most grateful.

The error message I get with the failed statement is either:

"Either BOF is true or EOF is true or the current record has been
deleted. Requested operation requires a current record"

or if I close an existing command connection I get

"Connection not valid",

Best wishes, John Morgan
 
Back
Top