Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2011
    Posts
    10

    form and field name as sub-routine parameters

    I have a couple of code segments that are very similar, and I want to replace them with a subroutine.

    The code opens a stores a value on the current form in a variable, opens a new form, and places the content of the variable in a text box on the new form.



    Dim Var_UserID As Long

    Var_UserID = Me.txt_StoreUserID
    DoCmd.OpenForm "frm_TechUseHome"
    [Forms]![frm_TechUseHome]![txt_HidUserID] = Var_UserID
    [Forms]![frm_TechUseHome].Refresh

    End Sub

    If I call this as a sub-routine, how will I pass the reference to the field and form?

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Why do you feel you need the variable?

  3. #3
    Join Date
    Jan 2011
    Posts
    10
    I don't understand your question...

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    The variable is not necessary:
    DoCmd.OpenForm "frm_TechUseHome"
    [Forms]![frm_TechUseHome]![txt_HidUserID] = Me.txt_StoreUserID

  5. #5
    Join Date
    Jan 2011
    Posts
    10
    so noted, thanx.

    How will I define this as a sub-routine, and pass the form and field names when I call it?

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You might try something like:
    Code:
    Private Sub Foo(TheForm As String, TheControl As String, TheValue As Variant)
     
       Forms(TheForm).Controls(TheControl) = TheValue
     
    End Sub
    ...but it hardly seems worth the effort.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 03-05-2011, 03:05 PM
  2. Replies: 3
    Last Post: 02-09-2011, 07:43 AM
  3. Contract Write Routine
    By pkstormy in forum Code Repository
    Replies: 0
    Last Post: 08-31-2010, 05:15 AM
  4. Example Importing routine
    By pkstormy in forum Code Repository
    Replies: 0
    Last Post: 08-24-2010, 12:35 AM
  5. applying a charge routine
    By rbrookes8dec in forum Access
    Replies: 1
    Last Post: 08-08-2010, 11:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums