Results 1 to 5 of 5

Thread: Newbie Q: Retrieve values stored in a module (Access 2000)

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Location
    Leeds
    Posts
    72

    Newbie Q: Retrieve values stored in a module (Access 2000)

    Hi.

    I have a module with the following:

    Option Compare Database

    Public strMyName As String


    strMyName takes the value of a text field on a form after I click a command button:

    strMyName = Me.cboFirstname.Value

    The Q is, how do I collect the value of strMyName and use throughout the application (in form lables etc).

    Thanks,

    jb

  2. #2
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951
    I think you have 3 choices:

    1. Just hide the form and done't close it. Then refer to the field (ie; formname.fieldname.text)

    2. Create a Global variable in a module and move the value to there

    3. Create a public variable on the form and hide the form.

  3. #3
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343
    On the On_Load event of the form put
    VB Code:
    1. FillForm

    In a module, define a public sub FillForm:
    VB Code:
    1. public sub FillForm(byref frmMe as form)
    2.     frmMe.lblMyName.caption = strMyName
    3. end sub


    Something like that, with a label lblMyName on each form you place the fillform call on.



    Vince

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Location
    Leeds
    Posts
    72
    Thanks for the help guys.

    I'm working with the code suggested by ecniv, just to expand, how would I then retrieve that value and use in a query to filter on firstnames for example:

    strMyName = "James"

    SELECT * FROM tblUsers WHERE Firstname = [strMyName]

    strMyName being a public sub in a module

    Thanks again

    jb

  5. #5
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343
    Depends if you are setting that sql statement via code (string manipulation) or via query/query builder (need a function).

    Sql statement - code
    Code:
    strSql = "select blah from blah where blah='" & strMyName &"'"
    Note the single quotes - for more info see the second sticky post on the forum lists.


    In a query
    VB Code:
    1. public function GetMyName() as string
    2.     GetMyName = strMyName
    3. end function
    In the query builder - where clause part put - GetMyName
    Note: This should work in Access, but not in Sql server etc..


    Vince

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width