Results 1 to 11 of 11
  1. #1
    MattLewis is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2016
    Posts
    17

    What am I missing here

    In the code below, when Form_BeforeInsert runs, it's not giving me the value that was set previously when Form_Open ran. Why not?

    Code:
    Option Explicit
    
    
    Private m_InternalJobRef As Long
    
    
    Private Sub Form_BeforeInsert(Cancel As Integer)
      MsgBox m_InternalJobRef
    End Sub
    
    
    Private Sub Form_Open(Cancel As Integer)
      If Not IsNull(OpenArgs) Then
        m_InternalJobRef = CLng(OpenArgs)
        MsgBox m_InternalJobRef
      End If
    End Sub
    Yes, I realize I could OpenArgs from within Form_BeforeInsert, but I'm just learning VBA programming, and I want to understand why on God's green Earth do so many things not work like they are supposed to.

  2. #2
    Micron is online now Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    I see no reason why it wouldn't work as written. When you say it doesn't give you the value, do you mean in the msgbox of the BeforeUpdate event or somewhere else, like in the immediate window? I tried to replicate your issue, but it works for me.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Like Micron, I can't reproduce your problem, either, which makes me wonder if the problem lies in the command, from another Form, that opens this Form; could you post it?

    Also, this code,using the Before_Insert event, presumably applies to a New Record, but I see no evidence of you going to a such...is the Form's Data Entry Property set to Yes?

    Linq ;0)>

  4. #4
    MattLewis is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2016
    Posts
    17
    The message box that shows in Sub Form_BeforeInsert comes up with 0, even though the value is being set prior to that during Sub Form_Open.

  5. #5
    Micron is online now Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    The only other idea I have at present is to temporarily take off the Clng coercion and/or make the global a variant for testing.
    EDIT: mistakenly referred to variable as global. Meant to refer to its scope as being at the module level.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by MattLewis View Post
    even though the value is being set prior to that during Sub Form_Open.
    Once again...since neither Micron nor I can reproduce the problem...I suspect that what you think is 'setting the value' isn't, in fact, setting the value! Which I why I asked for your code being used to open the Form, presumably from another Form.

    Linq ;0)>

  7. #7
    MattLewis is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2016
    Posts
    17
    Get over the OpenArgs part of this. That functionality is working. What's not working is when I set a variable in one sub, it's not sticking for later use by other subs.
    Attached Files Attached Files

  8. #8
    MattLewis is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2016
    Posts
    17
    **** it. I'll just use a TextBox on the form, set it to visible=no, and use that to store my string.

  9. #9
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by MattLewis View Post
    Get over the OpenArgs part of this. That functionality is working. What's not working is when I set a variable in one sub, it's not sticking for later use by other subs.
    This also works, as intended, when I run it!

  10. #10
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Not sure if this is the issue or not, but try changing

    Private m_InternalJobRef As Long
    to
    Dim m_InternalJobRef As Long

    Also check that the variable m_InternalJobRef is not declared (as Private or Dim) in another procedure in the same module, which could easily cause the problem you are having.

  11. #11
    Micron is online now Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    A variable Dim'd without an explicit scope keyword is Private by default, so the two declarations are the same.
    That would also mean that if declared that way in another module, it would be private to that module regardless of which of those two declarations was used.
    Without being able to see the actual code that opens the other form I think there's not much more that we can do. As noted, it works for at least two of us. I tested as written in the first post, including using the BeforeUpdate event to get the value.
    Last edited by Micron; 11-15-2016 at 09:50 AM. Reason: clarification

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

Similar Threads

  1. What am I missing please?
    By arrudac30 in forum Access
    Replies: 6
    Last Post: 08-14-2015, 05:30 PM
  2. Web GUI am I missing it?
    By Runningace in forum Database Design
    Replies: 1
    Last Post: 02-15-2014, 01:24 AM
  3. What am I missing???
    By tyewonk in forum Access
    Replies: 4
    Last Post: 10-14-2013, 12:07 PM
  4. What am I missing????
    By Loc in forum Queries
    Replies: 6
    Last Post: 05-25-2013, 07:11 PM
  5. What is missing in it?
    By cap.zadi in forum Forms
    Replies: 7
    Last Post: 10-05-2011, 12:47 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