How to select and go to record from a list box?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ryno Bower
    New Member
    • Nov 2010
    • 76

    #1

    How to select and go to record from a list box?

    Good day
    I need some help to do the following.
    *
    I am busy writing a program for inventory management, dealing with the operators, customers, suppliers etc.
    *
    I have two foms called: "OperatorDetail s" and "EditOperat or"
    *
    On the form "OperatorDetail s" I have a search button and when clicked it opens "EditOperat or" showing all the operators in the database.
    *
    On the form "EditOperat or" I have a listbox containing all the information on the underlying table called "AdmOperato rs".
    The table "AdmOperato rs" have fields like "Operator (PK and is NOT a autonumber),Loc ation, IsAdministrator etc.
    *
    So all that I want to happen is that when I double click on a record in the listbox, it must take that specific "Operator" and fill it into a textbox on the form "OperatorDetail s" called "txtEditOperato r", then go to that specific record.
    *
    I know that I could use like a combobox in the "OperatorDetail s" form, but I wat it this way for some other reasons which is not applicable now.
    *
    If you think you can help me, please reply as soon as possible.
    *
    Thanking you in advance.
    *
    Ryno
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32669

    #2
    Does it help to know that you can pass an object reference to a form if you design that form with a public function to support that? With a reference to the calling form you can write your code to manipulate that form from within your called form. It can also be done with class objects (which is what I use for all my forms), but that's a little more involved and I won't go into that here without any specific interest being shown in that approach.

    I include below the basics of what's required to pass the calling form to the called form in your project :
    Calling Form
    Code:
    Call DoCmd.OpenForm("frmCalled", , , stLinkCriteria)
    Call Forms("frmCalled").PubProc(CallingForm:=Me)
    Called Form
    Code:
    Option Compare Database
    Option Explicit
    
    Private frmCallingForm As Form
    
    '... other code probably
    
    Public Sub PubProc(CallingForm As Form)
        Set frmCallingForm = CallingForm
    End Sub
    The code you would use to control any of the objects in the Calling Form from within the Called Form would refer to the Private Form object frmCallingForm and should probably check that it is not set to Nothing before use (just in case).

    Comment

    Working...