Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2014
    Location
    Pittsburgh, USA
    Posts
    28

    Unanswered: Value of Field is Global Variable

    Hi Everyone,

    I am creating a db where users enter Proposal information, and under the same proposal, there are several revisions with differing data. The 2 tables are linked.

    When the user presses a CREATE REVISION button, the new form (Revision Form) opens where people can enter the new data. On this form, and also in the Revisions table, I have placed a ProposalID field which should take the ProposalID value from the Proposal Form. At first, I had the DefaultValue of the ProposalID equals to the ProposalID from the Proposal Form. It worked. However, several forms also lead to this Revision form and so the Defult value taken from 1 previous form is not enough..

    Long story short, I assigned a global Variable in a module, and when the user presses CREATE REVISION, the variable copies the ProposalID and Opens the New Revision form, and copies the value in the ProposalID field there. It's not working.. The field shows blank.

    Module:

    Global PropID

    On CREATE REVISION:
    PropID = Me.ProposalID.Value
    DoCmd.Close acForm, Me.Name
    DoCmd.OpenForm Form_SCNewWWF.Name, , , , acFormAdd
    Form_SCNewWWF.ProposalID.Value = PropID

    I hope I didn't complicate things. Anyone knows what is wrong here?

    Thanks!!

    Randa

  2. #2
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    I'm not sure Access accepts 'Global.' Thry

    Public PropID As Integer

    or

    Public PropID As String

    whichever is appropriate.

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    Join Date
    Feb 2014
    Location
    Pittsburgh, USA
    Posts
    28
    Thanks Missingling.

    I used Global for other variables (to copy and paste), and it worked.

    I also tried it your way, but it also didn't work. It's giving me a blank value.. I have no idea what the problem is..

    Cheers,

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Quote Originally Posted by RandaAlameh View Post
    Long story short, I assigned a global Variable in a module, and when the user presses CREATE REVISION, the variable copies the ProposalID and Opens the New Revision form, and copies the value in the ProposalID field there. It's not working.. The field shows blank.

    Module:

    Global PropID

    On CREATE REVISION:
    PropID = Me.ProposalID.Value
    DoCmd.Close acForm, Me.Name
    DoCmd.OpenForm Form_SCNewWWF.Name, , , , acFormAdd
    Form_SCNewWWF.ProposalID.Value = PropIDAnyone knows what is wrong here?
    You complicate simple matters. Why dont you use:
    a) in the first form
    Code:
    DoCmd.OpenForm "SCNewWWF", , , , acFormAdd , , Me.ProposalID.Value
    DoCmd.Close acForm, Me.Name
    b) In the Form SCNewWWF:
    Code:
    Private Sub Form_Current()
    
        Me.ProposalID.Value = Me.OpenArgs
        
    End Sub
    Have a nice day!

  5. #5
    Join Date
    Feb 2014
    Location
    Pittsburgh, USA
    Posts
    28
    Dear Sinddho,

    Thanks! I'm new to access and didn't know that trick.

    I have another question. In my proposal form, I have the list of revisions as a subform. I count the revisions and when the user presses CREATE NEW REVISION, the revision number field is automatically inserted. Is there a way to pass it too?

    Thanks again,

    Randa

  6. #6
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Quote Originally Posted by RandaAlameh View Post
    Thanks! I'm new to access and didn't know that trick.
    You're welcome!
    Quote Originally Posted by RandaAlameh View Post
    In my proposal form, I have the list of revisions as a subform. I count the revisions and when the user presses CREATE NEW REVISION, the revision number field is automatically inserted. Is there a way to pass it too?
    You'll need to create a parser if you want to pass more than 1 value through the OpenArgs argument of the DoCmd.OpenForm method.

    Several solutions are available. The simplest consists in passing the arguments separated by a list separator when calling the DoCmd.OpenForm method, then splitting the received OpenArgs string. In the first form:
    Code:
    Dim strArgs As String
    Dim lngRevisionNumber As Long
    
    lngRevisionNumber = Nz(Me.listofrevisionssubform.RevisionNumber, 0) ' Change to the proper reference.
    strArgs = Nz(Me.ProposalID.Value,"") & ";" & lngRevisionNumber + 1
    DoCmd.OpenForm "SCNewWWF", , , , acFormAdd , , strArgs
    DoCmd.Close acForm, Me.Name
    Then in the second form:
    Code:
    Private Sub Form_Current()
    
        dim varArgs As Variant
    
        varArgs = Split(Me.OpenArgs, ";")
        Me.ProposalID.Value = varArgs(0)
        Me.RevisionNumber.Value = varArgs(1)
        
    End Sub
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •