Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4059278
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:11:16+00:00 2026-05-20T15:11:16+00:00

I’m writing a script which pulls out some patient data and generates an XML

  • 0

I’m writing a script which pulls out some patient data and generates an XML export.

Each patient record has an associated doctor – but rather than repeat doctor details in each record, I figured I’d set the doctor ID in the patient record, and then include a list of doctors in a different section at the bottom of the document.

One thing I need to do is included a GUID for the doctor in the patient record, but the actual database relationship is a local non-unique ID. I figured the best way forward was to map the GUIDs in a list of local IDs using a dictionary.

Anyway, long story short, here is the bit that builds the require list:

While Not PatientRec.EOF
    Set DoctorRec = MyDB.OpenRecordset("Select Lng_Key, Txt_GUID From Tbl_LU_DoctorDetail Where Lng_Key = " & PatientRec![Lng_Doctor])

    While Not DoctorRec.EOF
        If (IsNull(DoctorRec![Txt_GUID])) Then
            DoctorRec.Edit
            DoctorRec![Txt_GUID] = CreateGUID()
            DoctorRec.Update
        End If

        DoctorList.Add DoctorRec![Lng_Key], DoctorRec![Txt_GUID]

        ' outputs something like '5:{03f50fe1-a0a4-4733-906a-771e22845ea6}
        MsgBox (DoctorRec![Lng_Key] & ":" & DoctorList.Items(DoctorRec![Lng_Key]))

        DoctorRec.MoveNext
    Wend
Wend

' outputs nothing!
MsgBox (DoctorList.Item(5))

' but there is something in there???
MsgBox (DoctorList.count)

I’ve also tried casting the id to a string using CStr, but get the same result with DoctorList.Item(“5”)

Worse, when I try:

Dim v As Variant
For Each v In DoctorList.Keys
    MsgBox (v & ":" & DoctorList.Item(v))
Next

I get the error:

Run-time error '3420':

Object invalid or no longer set.

Testing (and the helpfile) indicates that the Variant ‘v’ is not being set to anything from the Keys property, but the For Each is at least attempting on loop…

— Update

I found a similar question by someone on vbforums: http://www.vbforums.com/showthread.php?t=622933

I tested with a hardcoded key and item:

DoctorList.Add 5, "String"

The For Each loop now runs once successfully, but then fails with the 3420 error on a second loop (even when it should have stopped on the first loop).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T15:11:17+00:00Added an answer on May 20, 2026 at 3:11 pm

    Found the problem – it appears that Dictionaries will happily use objects as keys, so when using the Dictionary.Add method you have to explicitly use the Value property of the field from the recordset:

    DoctorList.Add DoctorRec![Lng_Key].Value, DoctorRec![Txt_GUID].Value
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.