Results 1 to 8 of 8
  1. #1
    twgonder is offline Expert
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658

    Reference a control value from frm variable in sub procedure

    I asked something similar for DAO syntax, but now I've got the same question for a Form object variable.

    In a form is textbox, tbxNm1, which is bound to Nm1 in the table.
    I've called a procedure in another module and have passed the form object via: SomeProcedure(Frm As Form)



    Now I want to get the value for Nm1 that is in the form, from the Frm object.
    Based on the DAO solution I thought something like this might work:
    FldNm = "Nm1"
    ...
    vFld = Frm.Fields(FldNm).Value

    but no... (won't compile)

    Note, I can't use Frm!Nm1 because I'm actually loop processing a lot of fields (for error checking) by variable.

    What's the syntax?
    Thanks

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    try

    vFld = Frm("tbx" & FldNm)

    or maybe

    vFld = Frm.recordset.fields(FldNm)

    if frm is a continuous form, should return the value from the current record






  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,793
    FldNm = "Nm1"
    Think about how a computer responds to that: "Who the heck is FldNm" and to whom does s/he belong?
    Last edited by Micron; 11-15-2022 at 07:23 PM. Reason: correction
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    I think you're looking for:

    Code:
    vFld = Frm.Controls(FldNm)
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  5. #5
    twgonder is offline Expert
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658

    The next step to get the label caption for the textbox

    Quote Originally Posted by Gicu View Post
    I think you're looking for:

    Code:
    vFld = Frm.Controls(FldNm)
    Cheers,
    Yes, that works, and now to take it one step further...
    I'm working on the validation routine for the form.
    The label's caption, for a control, has been converted to foreign language.

    This works (it's more complicated than my first example in post 1)
    ?frm.Controls("tbxm_Nm1")
    Thomas

    This gets the same result:
    ?frm.Controls("tbxm_Nm1").value

    As well, I can do this:
    ?frm.Controls("tbxm_Nm1").name
    tbxm_Nm1

    Now I want to get the label name with this:
    ?frm.Controls("tbxm_Nm1").labelname (result: RTE 438; Object doesn't support this property or method)
    (I've tripled checked that the textbox's label is exactly as the label name)
    Is there a syntax problem or am I screwed in this endeavor?

    Ultimately, this is what I need (or with correct syntax) to get the translated label for the text/combo box:
    ?frm.Controls(frm.Controls("tbxm_Nm1").labelname). caption

    Note: In the code, "tbxm_Nm1" is replaced with a variable, I'm just testing with this in the immediate window to try and figure out the syntax)
    My Google search didn't reveal any tricks or syntax to use.

  6. #6
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    Try
    ?frm.Controls("tbxm_Nm1").Controls(0).Caption
    or
    ?frm.Controls("tbxm_Nm1").Controls.Item(0).Caption

    Some links for you:
    https://stackoverflow.com/questions/...t-from-control
    https://stackoverflow.com/questions/...ontrol-in-code

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  7. #7
    twgonder is offline Expert
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    658
    Quote Originally Posted by Gicu View Post
    Try
    ?frm.Controls("tbxm_Nm1").Controls(0).Caption
    or
    ?frm.Controls("tbxm_Nm1").Controls.Item(0).Caption
    ...
    Cheers,
    Great, both of those work. I'm not sure why, with the Controls(0) bit, but I'm off to read why.
    Thanks

  8. #8
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    Here is a very good reference:
    https://www.devhut.net/ms-access-vba...ociated-label/

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

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

Similar Threads

  1. Invalid Next Control Variable Reference
    By DMT Dave in forum Access
    Replies: 6
    Last Post: 03-05-2022, 01:21 PM
  2. Replies: 2
    Last Post: 05-14-2021, 08:39 AM
  3. Replies: 15
    Last Post: 05-12-2016, 02:27 PM
  4. Variable within form control reference
    By Tyork in forum Programming
    Replies: 2
    Last Post: 10-13-2010, 09:55 AM
  5. Return Procedure variable to VBA
    By allenjasonbrown@gmail.com in forum Programming
    Replies: 6
    Last Post: 06-15-2010, 08:49 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