Originally Posted by
manics31
<snip>
I have a button on a form that assigns a number based on fiscal year , month and a number 001-1000, so if I were to enter a new number to day it would be 18-09-0001 and so on, but for some mythological reason the numbers did not reset, <snip>
I didn't understand what wasn't "resetting" until aytee111 posted... (but I agree aytee111.. )
However, there are many, many other things to fix/correct in the code.
Here are a few. (this is not a slam on you. These things happen quite frequently )
The top two lines of EVERY code module should be
Code:
Option Compare Database
Option Explicit
In the IDE, click on TOOLS/OPTIONS/Editor. Check the 2nd check box "Require Variable Declaration". Any NEW modules created will have those two lines.
--------------------------------------
You have many variables that are not declared..
--------------------------------------
Lines like this:
Code:
Dim rslabs, rstest, rsdummy As Recordset
do not do what you think.
"rsdummy" is declared as a Recordset type; "rslabs" & "rstest" are declared as variants.
BAD:
Code:
Dim MyDB As Database
Dim myws As Workspace
Dim tselfind, rselfind As String
Dim rslabs, rstest, rsdummy As Recordset
Dim estcall As String
GOOD: EACH variable type MUST be declared explicitly, like this:
Code:
Dim MyDB As DAO.Database
Dim myws As Workspace
Dim tselfind As String, rselfind As String
Dim rslabs As Recordset, rstest As Recordset, rsdummy As Recordset
Dim estcall As String
--------------------------------------
BTW, these two lines
Code:
Dim MyDB As DAO.Database
Dim myws As Workspace
are effectively the same. I only use "DAO.Database".
--------------------------------------
Code:
DoCmd.Close acForm, "frm_CallNumber", acSaveNo
The "acSaveNo" is used after design changes of the form and does not affect the saving or not saving of data (records). See Help.
--------------------------------------
You create objects and open recordsets, but don't close the recordset or destroy objects.
The rule is "If you create it, destroy it. If you open it, close it".
You have a line: "MyDB.Close". You didn't open it, so you shouldn't close it".
But you DID create it using the SET command, so you should destroy it. You do that by using "Set MyDB = Nothing".
You opened several recordsets, so you should close them. Then, you also have to destroy them:
Code:
Set rstesting = MyDB.OpenRecordset("Testing", DB_OPEN_DYNASET)
.... other code
rstesting.close
Set rstesting = nothing
===============================================
Not a problem/error, but
These lines can be replaced with one line:
Code:
' If estnum <= 9 Then
' estnew = "000" & estnum
' ElseIf estnum > 9 And estnum < 100 Then
' estnew = "00" & estnum
' ElseIf estnum >= 100 And estnum < 1000 Then
' estnew = "0" & estnum
' ElseIf estnum >= 1000 Then
' estnew = estnum
' End If
estnew = Right("0000" & estnum, 4)
--------------------------------------
If you are referring to a control on a form in a form class module, it is better to prefix the control name with "Me."
Code:
Me.NuEst = Estdt & estnew