Results 1 to 11 of 11
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919

    Get record field value from general module


    I have a general module that needs a field value from the current record in a known form that has just had one of its record selectors given focus. So far, I've not hit upon the proper syntax:

    Code:
    lngRegID = Forms("frmRegistry").ActiveControl.Form([RegistryID])
    Not even sure I'm in the right "ball park"?

  2. #2
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    Can't you pass the value or control name to the sub?
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    I think you're expecting the ActiveControl to be a subform control. Is that the case, and is it even possible?
    Form(RegistryID) seems wrong too.
    What is the design setup/hierarchy?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    The Public Function gets called via a Right-Click CommandBar entry. There's not the usual direct access to record objects like a single-click on a form's Record Selector would be, so one has to obtain the record's field values with a different method, I'm just struggling a bit to figure out how to do that.

    In A2003, the problem didn't exist, as the Public Function for the Right-Click "On Action" could be located in the form's module and the form's controls and record field values were readily accessible in code, but that went away with the A2003

  5. #5
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Normally yes, but with CommandBar "On Action" from a Shortcut menu the world changes a bit and I'm tying to adjust to the difference.

  6. #6
    davegri's Avatar
    davegri is online now Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,412
    I just ran into a similar problem last week. I changed a stand-alone form to a subform and discovered that the custom right-click target function (in the subform's module) no longer worked. The function was trying to open another form. So I did as you did. I made a new right-click menu command to call a new defined function in a general module. That function had one line of code to call the ORIGINAL right click target function (now no longer a commandbar called function) in the subform.
    All pops, no bangs.
    Call Forms.frm_Main.[ctlSubform].Form.TargetFunction

    The target function in the subform must be Public.

    In A2003, the problem didn't exist, as the Public Function for the Right-Click "On Action" could be located in the form's module and the form's controls and record field values were readily accessible in code, but that went away with the A2003
    Probably did exist if the form was a subform.
    Last edited by davegri; 10-01-2022 at 09:19 PM. Reason: addd public comment

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    Code:
    lngRegID = Forms("frmRegistry").ActiveControl.Form("RegistryID")
    
    'or
    
    lngRegID = Forms("frmRegistry").ActiveControl.Form.RegistryID
    
    'or
    
    lngRegID = Forms("frmRegistry").ActiveControl!RegistryID
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    All three forms you suggested failed with the same error.
    Click image for larger version. 

Name:	001.jpg 
Views:	16 
Size:	33.2 KB 
ID:	48843

    Function xfrDelReg is the "On Action" property of the CommandBar. Function DelReg is the original unaltered Public Function within a general module. Initially, I tried to simply use that in the "On Action" property like it was used in A2003, i.e., =DelReg("RegistryID"), but that fails also.

    Code:
    Public Function xfrDelReg(dummy As Integer)Dim lngRegID As Long
    lngRegID = Forms("frmRegistry").ActiveControl!RegistryID
    'lngRegID = Forms("frmRegistry").ActiveControl.Form.RegistryID
    'lngRegID = Forms("frmRegistry").ActiveControl.Form("RegistryID")
    'lngRegID = Forms("frmRegistry").ActiveControl.Form([RegistryID])
    DelReg (lngRegID)
    End Function

  9. #9
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Yes, I've already done the call to the Public Function in a form's module successfully. It may be that I have to move the Public Function DelReg from the general module to the form's module, but that still leaves me lacking in the field value I need. I'll try that in the AM and see if the desired record still has the focus after the run around. It might prove a bit tricky, as function DelReg is sometimes operating on a clone RecordSource versus sometimes a query........ we'll see

  10. #10
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    They all worked in test with my db. But I was not using a function. I tested in the Immediate Window.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    The only way I've been able to find success is to move the Public Function DelReg code to the form's module, then route the "On Action" of the CommandBar through a Call to the DelReg function in the form's module. The amount of code in the DelReg function isn't particularly voluminous, so I guess it's a small price to pay to get the job done. The downside, IMHO, is I'll have to duplicate the code in another instance where the function is required.

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

Similar Threads

  1. General module calling public function in an open form
    By GraeagleBill in forum Programming
    Replies: 3
    Last Post: 09-30-2022, 02:08 PM
  2. position to last record on a form from general module
    By GraeagleBill in forum Programming
    Replies: 6
    Last Post: 09-07-2021, 01:13 PM
  3. Force a Requery from general module
    By GraeagleBill in forum Programming
    Replies: 10
    Last Post: 07-10-2018, 09:01 AM
  4. How to cause a form event to fire from a general module
    By GraeagleBill in forum Programming
    Replies: 10
    Last Post: 09-04-2016, 08:08 AM
  5. General Module - Implementing LiFo Stack
    By GraeagleBill in forum Programming
    Replies: 2
    Last Post: 05-13-2014, 01:15 PM

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