Keychain Access

When retrieving a KeyChainItem I don’t seem to be getting the AccountName property back.

Creating the items as follows:

  Dim NewItem as KeyChainItem
  
  if chkUseKeyChain.Value = true then
    
    If System.KeyChainCount > 0 then
      
      NewItem = New KeyChainItem
      'Indicate the name of the application
      NewItem.ServiceName = app.kAppBundleID
      NewItem.AccountName = txtUsername.Text
      
      'Create a new keychain item for the application and assign the password
      System.KeyChain.AddPassword NewItem, txtPassword.Text
    Else
      Beep
      MsgBox "You don't have a key chain."
    End if
    
  end if
  
Exception err as KeyChainException
  MsgBox "Can't add item: " + err.Message
  

Retrieving it as follows:


  Dim ItemToFind as KeyChainItem
  Dim password As String
  
  ItemToFind = New KeyChainItem
  
  'Indicate the name of the application whose keychain item you wish to find
  ItemToFind.ServiceName = app.kAppBundleID
  
  if ItemToFind <> Nil then
    
    frmMain.chkUseKeyChain.Value = True
    //Retrieve the account username
    frmMain.txtUsername.Text = ItemToFind.AccountName
    //get application's password from the system keychain
    password = System.KeyChain.FindPassword(ItemToFind)
    frmMain.txtPassword.Text = password
    
  end if
  
Exception err as KeyChainException
  MsgBox "Can't find item: " + err.Message

txtUsername ends up blank but it should be displaying the AccountName from Keychain. Any advice?

Has anyone used Keychain as above. I have followed instructions in the LR but it appears not to be working.