I
Iram
Hello.
I am having a hard time getting some code to work that is supposed to auto
fill a field with the next available number. I have a button on a data entry
form and on the "On Click" of the button I have =NextNWNumber(), which points
to a Module called "mdl_NextNWNumber". In this Module I have the following
code...
Option Compare Database
Option Explicit
Public Function NextNWNumber() As Long
Dim myrecs As Recordset
Set myrecs = CurrentDb.OpenRecordset("tbl_NWNumbersUsed")
NextNWNumber = myrecs!NWNumber
myrecs.Edit
myrecs!NWNumber = myrecs!NWNumber + 1
myrecs.Update
myrecs.Close
Set myrecs = Nothing
End Function
Here is a summary of the tables, fields and Modules of this db.
*Main table for data entry "tbl_Questionnaire". This table has many fields
however the main field that needs to be autofilled with the next available
number via the button on the form is "CalwinNumb" . This is a Text field
because we some times need to type in our own number with letters when we
don't use the auto fill button.
*Seperate table to store all of the next available numbers used
"tbl_NWNumbersUsed". There is only one field in this table called "NWNumber".
And there is only one record in this table which is 5000. This is the number
that I want the autofill number to start with, then sequence +1 from here on
all new data entry records. This is a Number field.
Can you help me figure out why my code doesn't produce the next avail number
starting from 5000? When I click on the button nothing happens, no errors.
Thanks.
Iram
I am having a hard time getting some code to work that is supposed to auto
fill a field with the next available number. I have a button on a data entry
form and on the "On Click" of the button I have =NextNWNumber(), which points
to a Module called "mdl_NextNWNumber". In this Module I have the following
code...
Option Compare Database
Option Explicit
Public Function NextNWNumber() As Long
Dim myrecs As Recordset
Set myrecs = CurrentDb.OpenRecordset("tbl_NWNumbersUsed")
NextNWNumber = myrecs!NWNumber
myrecs.Edit
myrecs!NWNumber = myrecs!NWNumber + 1
myrecs.Update
myrecs.Close
Set myrecs = Nothing
End Function
Here is a summary of the tables, fields and Modules of this db.
*Main table for data entry "tbl_Questionnaire". This table has many fields
however the main field that needs to be autofilled with the next available
number via the button on the form is "CalwinNumb" . This is a Text field
because we some times need to type in our own number with letters when we
don't use the auto fill button.
*Seperate table to store all of the next available numbers used
"tbl_NWNumbersUsed". There is only one field in this table called "NWNumber".
And there is only one record in this table which is 5000. This is the number
that I want the autofill number to start with, then sequence +1 from here on
all new data entry records. This is a Number field.
Can you help me figure out why my code doesn't produce the next avail number
starting from 5000? When I click on the button nothing happens, no errors.
Thanks.
Iram