Results 1 to 4 of 4
  1. #1
    fret hack is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    13

    Passing Values from one form to another

    Hello All,



    Im passing a value "UserID" from a switchboard form to another form ("Discharges") using this code:

    Code:
    Private Sub cmdDischarges_Click()
    
    Dim UserID As Integer
    
    UserID = Me.txUserID
    
    DoCmd.OpenForm "Discharges"
    Forms![Discharges]!txUserID = UserID
    End Sub
    On "Discharges" I have set up an lock/edit control that works well. I am attempting to only allow a record to be edited by the person assigned to that record (the "Reviewer"), but still allow all records to be readable. My hope is to accomplish this by disabling the lock/edit control for all unassiged Reviewers. This is the code that Im using currently to disable the lock/edit control:

    Code:
    Private Sub Form_Current()
    If Me.NewRecord Then
    Else
    
    If Me.txUserID <> Me.txReviewer Or IsNull(Me.txReviewer) Then
    Me.cmdEdit.Enabled = False
    End If
    
    End If
    End Sub
    The UserID value passes from the Switchboard form to the Discharges form, but editing for all records is disabled. However, if I manually enter a UserID into Me.txUserID on the Discharges form, the code works perfectly. Any suggestions on how to get this to work properly? Seems like it should be simple stuff, but Im a VBA novice.

    Thank you in advance for your help!

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    I would use the OpenArgs argument of OpenForm to pass value to Discharges form.

    DoCmd.OpenForm "Discharges", , , , , , Me.txUserID

    Then code behind Discharges would look for value in its OpenArgs property to set value of txUserID.

    If Not IsNull(Me.OpenArgs) Then
    ...
    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
    knarfreppep is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Feb 2015
    Location
    Adelaide, Australia
    Posts
    106
    Why not, on log on, populate a global variable e.g. gintOperatorID which can thereafter be accessed from anywhere?

  4. #4
    fret hack is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    13
    Quote Originally Posted by June7 View Post
    I would use the OpenArgs argument of OpenForm to pass value to Discharges form.

    DoCmd.OpenForm "Discharges", , , , , , Me.txUserID

    Then code behind Discharges would look for value in its OpenArgs property to set value of txUserID.

    If Not IsNull(Me.OpenArgs) Then
    ...
    Worked very well...thank You!

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

Similar Threads

  1. Passing values to another form
    By jlt199 in forum Forms
    Replies: 11
    Last Post: 02-25-2014, 04:50 PM
  2. Passing multiple values to a second form
    By WithoutPause in forum Forms
    Replies: 39
    Last Post: 02-12-2014, 04:03 PM
  3. Passing Form Values - Deleting Duplicates
    By sonoamore in forum Programming
    Replies: 4
    Last Post: 12-07-2013, 02:09 AM
  4. passing values from form to query
    By gregd in forum Access
    Replies: 6
    Last Post: 05-02-2013, 03:18 PM
  5. Replies: 5
    Last Post: 10-15-2012, 12:18 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