Greetings!
I'm working on a salemsan activity tracking database. The users want to group all activity they enter during a single editing session into a batch. To do that, I added code to my form's ON-OPEN event that looks up the largest existing batch number and adds one to it, as follows:
Dim myapp As Object
Dim myRS As Object
Dim mySQL As String
mySQL = "select max(batchnumber) as batchnumber from tblDSMActMaster"
Set myRS = CreateObject("ADODB.Recordset"
Set myapp = Application.CurrentProject.Connection
myRS.Open mySQL, myapp, 1
If IsNull(myRS![BatchNumber]) Then
DSMBatch = 1
Else
DSMBatch = myRS![BatchNumber] + 1
End If
myRS.Close
DSMBATCH is declared as a PUBLIC integer variable at the top of this module. Whenever a new record is entered I want to assign the batch number to the table column, but if a pre-existing record is being edited, I don't want to re-assign the batch number. So in the forms BEFORE-UPDATE event I put the following code:
If IsEmpty(Me.BatchNumber) Or IsNull(Me.BatchNumber) Or Me.BatchNumber = 0 Then
Me.BatchNumber = DSMBatch
End If
Perhaps the combination of empty, null, and equal zero is overkill, but I'm trying to make sure that I always assign the new batch number on a new record.
Most of the time, this works perfectly. However, occasionally the batch number column in the table will end up being zero for some part of a batch. Usually the user will start entering a batch and some of the records will go in with the correct batch number, but then the remainder of the batch will be all zero batch numbers. They generally don't notice this until they've entered a significant amount of data, then I have to go into the table and figure out what the correct batch numbers are and patch them in. During my debugging attempts, I've discovered that somehow the value stored in the variable DSMBatch is being reset to zero, which then results in all the records going into the table as batch zero. I don't have any other code that's resetting this batch number.
So far I haven't discovered any particular thing that triggers the batch variable being reset. It appears to occur entirely at random, but there may well be something that triggers it that I haven't recognized yet. Anybody got any ideas what might be causing this? Does the fact that DSMBatch is a public variable have anything to do with it?
Any ideas greatly appreciated,
Dale Beitz
dale.beitz@agreliantgenetics.com
I'm working on a salemsan activity tracking database. The users want to group all activity they enter during a single editing session into a batch. To do that, I added code to my form's ON-OPEN event that looks up the largest existing batch number and adds one to it, as follows:
Dim myapp As Object
Dim myRS As Object
Dim mySQL As String
mySQL = "select max(batchnumber) as batchnumber from tblDSMActMaster"
Set myRS = CreateObject("ADODB.Recordset"
Set myapp = Application.CurrentProject.Connection
myRS.Open mySQL, myapp, 1
If IsNull(myRS![BatchNumber]) Then
DSMBatch = 1
Else
DSMBatch = myRS![BatchNumber] + 1
End If
myRS.Close
DSMBATCH is declared as a PUBLIC integer variable at the top of this module. Whenever a new record is entered I want to assign the batch number to the table column, but if a pre-existing record is being edited, I don't want to re-assign the batch number. So in the forms BEFORE-UPDATE event I put the following code:
If IsEmpty(Me.BatchNumber) Or IsNull(Me.BatchNumber) Or Me.BatchNumber = 0 Then
Me.BatchNumber = DSMBatch
End If
Perhaps the combination of empty, null, and equal zero is overkill, but I'm trying to make sure that I always assign the new batch number on a new record.
Most of the time, this works perfectly. However, occasionally the batch number column in the table will end up being zero for some part of a batch. Usually the user will start entering a batch and some of the records will go in with the correct batch number, but then the remainder of the batch will be all zero batch numbers. They generally don't notice this until they've entered a significant amount of data, then I have to go into the table and figure out what the correct batch numbers are and patch them in. During my debugging attempts, I've discovered that somehow the value stored in the variable DSMBatch is being reset to zero, which then results in all the records going into the table as batch zero. I don't have any other code that's resetting this batch number.
So far I haven't discovered any particular thing that triggers the batch variable being reset. It appears to occur entirely at random, but there may well be something that triggers it that I haven't recognized yet. Anybody got any ideas what might be causing this? Does the fact that DSMBatch is a public variable have anything to do with it?
Any ideas greatly appreciated,
Dale Beitz
dale.beitz@agreliantgenetics.com