Hi all,
I'm relatively new to vba in Access and would approctae any help anyone may be able to offer.
I have the following vba code in my database, in order to add new records based on the last number in the table.
Private Sub PopulateDataGen_Click()
Dim barcodeLim As Long
Dim currentBarcode As String
Dim dbArtifacts As DAO.Database
Dim rstGeneral As DAO.Recordset
Set dbArtifacts = CurrentDb
Set rstGeneral = dbArtifacts.OpenRecordset("Data_General", dbOpenDynaset)
currentBarcode = [Forms]![Create Barcodes]![MaxOfBarcode] + 1
barcodeLim = [Forms]![Create Barcodes]![NumNewCodes] + [Forms]![Create Barcodes]![MaxOfBarcode] + 1
Do Until currentBarcode = barcodeLim
rstGeneral.AddNew
rstGeneral("Barcode").Value = currentBarcode
rstGeneral("Artifact Type").Value = [Forms]![Create Barcodes]![Artifact Type]
rstGeneral("Site").Value = [Forms]![Create Barcodes]![Site]
rstGeneral("Bed").Value = [Forms]![Create Barcodes]![Bed]
rstGeneral("Level").Value = [Forms]![Create Barcodes]![Level]
rstGeneral("Trench").Value = [Forms]![Create Barcodes]![Trench]
rstGeneral.Update
currentBarcode = currentBarcode + 1
Loop
rstGeneral.Close
DoCmd.Requery
[Forms]![Create Barcodes]![NumNewCodes] = Null
MsgBox "Records Added To Database"
End Sub
I was wondering if anyone would know how to have the new entries created in this code have the format of "0000000000". these new entries come under the "barcode" field.
any help would be hugely appreciated
all the best
Tom
I'm relatively new to vba in Access and would approctae any help anyone may be able to offer.
I have the following vba code in my database, in order to add new records based on the last number in the table.
Private Sub PopulateDataGen_Click()
Dim barcodeLim As Long
Dim currentBarcode As String
Dim dbArtifacts As DAO.Database
Dim rstGeneral As DAO.Recordset
Set dbArtifacts = CurrentDb
Set rstGeneral = dbArtifacts.OpenRecordset("Data_General", dbOpenDynaset)
currentBarcode = [Forms]![Create Barcodes]![MaxOfBarcode] + 1
barcodeLim = [Forms]![Create Barcodes]![NumNewCodes] + [Forms]![Create Barcodes]![MaxOfBarcode] + 1
Do Until currentBarcode = barcodeLim
rstGeneral.AddNew
rstGeneral("Barcode").Value = currentBarcode
rstGeneral("Artifact Type").Value = [Forms]![Create Barcodes]![Artifact Type]
rstGeneral("Site").Value = [Forms]![Create Barcodes]![Site]
rstGeneral("Bed").Value = [Forms]![Create Barcodes]![Bed]
rstGeneral("Level").Value = [Forms]![Create Barcodes]![Level]
rstGeneral("Trench").Value = [Forms]![Create Barcodes]![Trench]
rstGeneral.Update
currentBarcode = currentBarcode + 1
Loop
rstGeneral.Close
DoCmd.Requery
[Forms]![Create Barcodes]![NumNewCodes] = Null
MsgBox "Records Added To Database"
End Sub
I was wondering if anyone would know how to have the new entries created in this code have the format of "0000000000". these new entries come under the "barcode" field.
any help would be hugely appreciated
all the best
Tom