Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Dec 2003
    Location
    Bahamas
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    2 Access/VB Questions

    1) How do I get global variables in reports?
    I have several reports which have values which are subject to change. I tried declaring them as global in a module along with the rest of my globals . But the reports claim the values are undefined. I do not want to have to change 15 reports every time one of the rates change

    2) When I create a new record, the record number is apparently not defined until I save the record. In my project I have several users entering transactions, the transaction number is made up in part by the record number. I want to ensure that all transactions numbers are unique. I tried "locking" the table but because I have a bit of processing between record creation and saving. Its slowing my system down. P'haps I have poor design.

    Of course the work around would be create the record immediately saveit then do my processing then updsate the record. But that is awkward

  • #2
    Super Moderator sage45's Avatar
    Join Date
    May 2002
    Posts
    1,059
    Thanks
    0
    Thanked 13 Times in 13 Posts
    In VB, to declare a variable as a public variable for access from any module within the application you must use Public as opposed to Dim.

    I.E.:

    Module #1
    Code:
    Option Explicit
    'All public variable declarations go here
    Public P1 As Integer
    Dim a As Integer
    
    Public Sub PM1a()
         Dim L1 As Variant
    End Sub
    
    Public Sub PM1b()
         Dim L2 As Integer
    End Sub
    
    Public Sub PM1c
         Dim L3 As Integer
    End Sub
    Module #2
    Code:
    Option Explicit
    'All public variable declarations go here
    Public P2 As Integer
    Dim b As String
    
    Public Sub PM2a()
         Dim L2a As Single
    End Sub
    
    Public Sub PM2b()
         Dim L2b As Single
    End Sub
    
    Public Sub PM2c()
         Dim L2c As Single
    End Sub
    Using the above code:

    Module #1
    Sub PM1a can use the variables P1, a, P2 and L1.
    Sub PM1b can use the variables P1, a, P2 and L2.
    Sub PM1c can use the variables P1, a, P2 and L3.

    Module #2
    Sub PM2a can use the variables P2, b, P1 and L2a.
    Sub PM2b can use the variables P2, b, P1 and L2b.
    Sub PM2c can use the variables P2, b, P1 and L2c.

    HTH,

    -sage-
    HTML & CSS Forum Moderator

    "If you don't know what you think you know, then what do you know."
    R.I.P. Derrick Thomas #58
    1/1/1967 - 2/8/2000

  • #3
    Super Moderator sage45's Avatar
    Join Date
    May 2002
    Posts
    1,059
    Thanks
    0
    Thanked 13 Times in 13 Posts
    As for the record question...

    It would essentially make more sense to use a sub routine that would change a variable whenever a new record is generated... You can then use this variable to help in the generation of the transaction number...

    Something like:

    Code:
    Private Sub LoadNewRecord(varCurrTrans)
         Static lNWRecordCount As Long
         Dim frmRD As frmRecord
    
         lNWRecordCount = lNWRecordCount + 1
         Set frmRD = New frmRecord
         frmRD.Caption = "Transaction " & varCurrTrans & lNWRecordCount
         frmRD.Show
    End Sub
    Without actually seeing your code, I can only throw out a logical demonstration.... Essentially what you would do is take your known (generation of transaction number) and split the generation up so that when a new record is created it can then assemble the parts of the transaction code and store them as a global or public variable... It could do this dynamically... Another item to consider would be the ensuring that the Static in this case does not reset to 0 as it would do if you were to use the code as is... I would suggest dumping the variable to either a reg entry, tmp file or ini file on the server when the application is closed. And then when the application starts back up it set's the variable in accordance with the last known variable at shutdown...

    -sage-
    HTML & CSS Forum Moderator

    "If you don't know what you think you know, then what do you know."
    R.I.P. Derrick Thomas #58
    1/1/1967 - 2/8/2000


  •  

    Posting Permissions

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