...

View Full Version : 2 Access/VB Questions



trsands
01-12-2004, 05:54 PM
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

sage45
01-14-2004, 09:13 AM
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

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

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-

sage45
01-14-2004, 09:36 AM
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:



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-



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum