Prompt user to enter batch number for new records similar to autonumber..

J

jeremy0028

What i want the below code to do is when user clicks create batch will
ask user do you wish for access assign batch number for new records if
yes the code will run as is if user clicks no will take them to a form
for them to enter the batchnmber manually and will assign that number
to all new records. I know will will have to create a new form for
this part but dont know how to code it.

Thanks in advance.


Basically I have a table call tblBatch

BatchID(PK)
BatchNumber
BatchDateTime

tblMember
MemberID(PK)
Surname
Firstname
BatchID
BatchNumber


Private Sub cmdCreateBatch_Click()
'On Error GoTo Err_Handler
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSql As String
Dim lngBatchID As Long
Dim lngKt As Long

'Create the new batch, and get the number.
Set db = CurrentDb()
Set rs = db.OpenRecordset("tblBatch", dbOpenDynaset, dbAppendOnly)
rs.AddNew
rs!BatchDateTime = Now()
lngBatchID = rs!BatchID
rs.Update
rs.Close

'Give this batch number to all members who have not been printed.
strSql = "UPDATE tblMember SET BatchID = " & lngBatchID & " WHERE
BatchID Is Null;"
db.Execute strSql, dbFailOnError
lngKt = db.RecordsAffected

'Show the response.
Me.lstBatch.Requery
MsgBox "Batch " & lngBatchID & " contains " & lngKt & "
member(s)."

Exit_Handler:
Set rs = Nothing
Set db = Nothing
Exit Sub

Err_Handler:
MsgBox "Error " & Err.Number & ": " & Err.Description,
vbExclamation, "cmdCreateBatch_Click()"
Resume Exit_Handler
End Sub

Private Sub cmdPrintBatch_Click()
'On Error GoTo Err_Handler
Dim strWhere As String
Const strcDoc = "rptMemberList"

If IsNull(Me.lstBatch) Then
MsgBox "Select a batch to print."
Else
'Close the report if it's already open (so the filtering is
right.)
If CurrentProject.AllReports(strcDoc).IsLoaded Then
DoCmd.Close acReport, strcDoc
End If
'Open it filtered to the batch in the list box.
strWhere = "BatchID = " & Me.lstBatch
DoCmd.OpenReport strcDoc, acViewPreview, , strWhere
End If

Exit_Handler:
Exit Sub

Err_Handler:
MsgBox "Error " & Err.Number & ": " & Err.Description,
vbExclamation, ".cmdPrintBatch_Click"
Resume Exit_Handler
End Sub

Private Sub cmdUndoBatch_Click()
'On Error GoTo Err_Handler
Dim db As DAO.Database
Dim strSql As String
Dim varBatchID As Variant
Dim lngKt As Long

'Get the highest batch number.
varBatchID = DMax("BatchID", "tblBatch")
If IsNull(varBatchID) Then
MsgBox "No batches found."
Else
'Clear all the members of the batch.
Set db = CurrentDb()
strSql = "UPDATE tblMember SET BatchID = Null WHERE BatchID =
" & varBatchID & ";"
db.Execute strSql, dbFailOnError
'Delete the batch.
strSql = "DELETE FROM tblBatch WHERE BatchID = " & varBatchID
& ";"
db.Execute strSql, dbFailOnError
lngKt = db.RecordsAffected

'Show the response.
Me.lstBatch.Requery
MsgBox "Batch " & varBatchID & " deleted. " & lngKt & "
member(s) marked as not printed."
End If

Exit_Handler:
Set db = Nothing
Exit Sub

Err_Handler:
MsgBox "Error " & Err.Number & ": " & Err.Description,
vbExclamation, ".cmdUndoBatch_Click"
Resume Exit_Handler
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top