Results 1 to 3 of 3
  1. #1
    Karlos51 is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2025
    Posts
    2

    How to access the value of control.colomn(x) after passing the control to a global function

    Inexperienced user here.
    I have multiple forms within my database in which I copy the value of one control to another, some of them are ComboBox controls for which I use the value from a particular column. Currently I use a separate button and VBA sub for each instance, which works fine.
    I have been trying to simplify this with a single global function that I can call with a macro to accomplish this task, but I seem to be unable to access the control.Column(x) value when using this method.
    My global function looks like this (I use a function as it seems I cannot call a sub from a macro):
    Code:
    Function copy_value(FromControl, ToControl As Control, Optional col As Long = 0)    
    If col = 0 Then
            ToControl.Value = FromControl.Value
        Else
            ToControl.Value = FromControl.Column(col).Value
        End If
    End Function
    Works fine for controls without the Column property, but fails with error 424 otherwise.
    Is there a way to make this work, or a better way to achieve this?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Don't use Value property when pulling from Column.

    Value is property of control, not Column.

    Why use macros at all?

    You have not declared data type for FromControl.
    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.

  3. #3
    Karlos51 is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2025
    Posts
    2
    Quote Originally Posted by June7 View Post
    Don't use Value property when pulling from Column.

    Value is property of control, not Column.

    Why use macros at all?

    You have not declared data type for FromControl.

    OMG, it really was as simple as removing the .value. Thank you.
    I was using a macro to try and simplify the codebase as the other people here are even less experienced than I.

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

Similar Threads

  1. Replies: 11
    Last Post: 04-16-2021, 10:59 AM
  2. Replies: 17
    Last Post: 02-25-2018, 02:37 AM
  3. Passing Global Constants to controls on a report
    By Carbontrader in forum Reports
    Replies: 1
    Last Post: 05-10-2017, 12:17 PM
  4. Passing global variables question
    By newbieX in forum Programming
    Replies: 6
    Last Post: 10-03-2014, 02:09 PM
  5. Create global function to calculate tax week
    By haylau in forum Programming
    Replies: 4
    Last Post: 03-15-2011, 10:31 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