Get document from current doc key field

Experts,

I have a form (document A) that has a field called "WebCompanyNumber".  I have another form (document B) called "CompanyProfile" that also has the same field: WebCompanyNumber.  These documents do not have a Parent/Child relationship.

The company profiles have unique values in the WebCompanyNumber.  When a user is in document B, I want the user to click a button to display the company profile, based on the value in document B.  I have a view that has docs from document A and the first column is WebCompanyNumber (hidden).  Both documents A & B are imported from another non-Notes application, so I cannot grab the docUNID to make this easier.

I have created the following code, but is not working.  I get a error "object variable not set" and debugger goes on the following line:
Set dc=view.GetAllDocumentsByKey(Cstr(curdoc.WebCompanyNumber(0)),True)

Here is my code:
========================================================
Sub Click(Source As Button)
      Dim ws As New NotesUIWorkspace
      Dim uidoc As NotesUIDocument
      Dim curdoc As NotesDocument
      Dim session As New NotesSession
      Dim db As  NotesDatabase
      Dim view As NotesView
      Dim doc As NotesDocument
      Dim dc As NotesDocumentCollection
      
      Set uidoc=ws.CurrentDocument
      Set curdoc=uidoc.document
      
      Set db=session.CurrentDatabase
      Set view=db.GetView("(CompanyAll)")
      
      'This gets the documents with the same WebCompanyNumber
      Set dc=view.GetAllDocumentsByKey(Cstr(curdoc.WebCompanyNumber(0)),True)
      Set doc=dc.GetFirstDocument

      'Open the company profile document that matches the WebCompanyNumber      
      If Not doc Is Nothing Then
            Set uidoc = ws.EditDocument(False,doc)
      End If
      
End Sub
Thanks in advance,
AliciaVee
AliciaVeeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ZvonkoSystems architectCommented:
Are you sure that those first column in the View "(CompanyAll)" is Sorted?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ZvonkoSystems architectCommented:
Also show the value of curdoc.WebCompanyNumber(0) in the status bar by a Print statement.
I supose that value is empty and you should use FieldGetText()
AliciaVeeAuthor Commented:
Zonko,

You are right -- I did not have the column in the view sorted.  So I did that, and it worked! DUH!!

I was also trying this code below, but it wasing working either -- thinking, gosh, it is so much simpler than my LotusScript -- what could be wrong?  Sorted column!.  Didn't know that (I must have missed it in the post).
http://www.experts-exchange.com/Applications/Email/Lotus_Notes_Domino/Q_10170833.html?query=FileOpenDatabase&topics=133

@Command([FileOpenDatabase]; server : database  ; viewName ; key ; "1");
@Command( [EditDocument] ; "0");
@Command([FileOpenDatabase]; server : database  ; viewName ; key ; "0");
@Command([FileCloseWindow])

Works great now!
Thanks a bunch,
AliciaVee
AliciaVeeAuthor Commented:
I should probably add the code I used, just in case someone else needs it - as I changed it a bit to look to the current database:

Initiated from a button on the form:

key := WebCompanyNumber;
@Command([FileOpenDatabase]; ""; "(CompanyNumberSort)"; key; "1");
@Command([EditDocument];"0");
@Command([FileOpenDatabase]; ""; "(CompanyNumberSort)"; key; "0");
@Command([FileCloseWindow])

WebCompanyNumber is a field in the current document, where the [View Company Profile] is located.
ZvonkoSystems architectCommented:
Thanks for the feedback AliciaVee.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.