Hi All
I am fairly new to access and coding. I have an issue with a form as follows:
The form is unbound as it update two different table when the "Add Record" button is clicked.
Within the form are three check boxes, "Active", "GST Applicable" and "MinStockSelect"
I have code to ensure that the other fields are not null which is triggered by the Add Record button.
My issue is that the checkbox field will create a new record before the other fields are completed when the Add Record is selected. As the checkboxes already contain a value I do not know how to prevent this.
My code is:
I need to prevent the checkbox fields from creating a record until the entire form is completed.
Would appreciate any assistance on this
Thanks
I am fairly new to access and coding. I have an issue with a form as follows:
The form is unbound as it update two different table when the "Add Record" button is clicked.
Within the form are three check boxes, "Active", "GST Applicable" and "MinStockSelect"
I have code to ensure that the other fields are not null which is triggered by the Add Record button.
My issue is that the checkbox field will create a new record before the other fields are completed when the Add Record is selected. As the checkboxes already contain a value I do not know how to prevent this.
My code is:
Code:
Private Sub Add_Record_Click()
If IsNull(Me.DateAdded) Then
MsgBox "Please enter the date stock added!", vbCritical, "Missing Date"
Me.DateAdded.SetFocus
Exit Sub
End If
If IsNull(Me.Supplier) Then
MsgBox "Please select the supplier!", vbCritical, "Missing Supplier"
Me.Supplier.SetFocus
Exit Sub
End If
If IsNull(Me.Grp) Then
MsgBox "Please select the group for this stock item!", vbCritical, "Missing Group"
Me.Grp.SetFocus
Exit Sub
End If
If IsNull(Me.SubGrp) Then
MsgBox "Please select the sub group for this stock item!", vbCritical, "Missing Sub Group"
Me.SubGrp.SetFocus
Exit Sub
End If
If IsNull(Me.StockItem) Then
MsgBox "Please enter the stock description for this stock item!", vbCritical, "Missing Stock Description"
Me.StockItem.SetFocus
Exit Sub
End If
If IsNull(Me.Price) Then
MsgBox "Please enter the price for this stock item!", vbCritical, "Missing Price"
Me.Price.SetFocus
Exit Sub
End If
If IsNull(Me.Quantity) Then
MsgBox "Please enter the quantity for this stock item!", vbCritical, "Missing Quantity"
Me.Quantity.SetFocus
Exit Sub
End If
If IsNull(Me.SalePrice) Then
MsgBox "Please enter the selling price for this stock item!", vbCritical, "Missing Sale Price"
Me.SalePrice.SetFocus
Exit Sub
End If
If Me.MinStockSelect = True And Me.MinStock <= 0 Then
MsgBox "Please enter the minimum stock value!", vbCritical, "Missing Stock Value"
Me.MinStock.SetFocus
Exit Sub
End If
If Me.MinStockSelect = True And Me.StockCount <= 0 Then
MsgBox "Please enter the opening stock count", vbCritical, "Missing Stock Count"
Me.StockCount.SetFocus
Exit Sub
End If
Dim tblStock As DAO.Recordset
Set tblStock = CurrentDb.OpenRecordset("SELECT * FROM [tblStock]")
tblStock.AddNew
tblStock![DateAdded] = Me.DateAdded.Value
tblStock![StockItem] = Me.StockItem.Value
tblStock![GrpId] = Me.GrpId.Value
tblStock![Grp] = Me.Grp.Value
tblStock![SuGrpId] = Me.SubGrpId.Value
tblStock![SubGrp] = Me.SubGrp.Value
tblStock![Supplier] = Me.Supplier.Value
tblStock![SupplierId] = Me.SupplierId.Value
tblStock![Price] = Me.Price.Value
tblStock![Quantity] = Me.Quantity.Value
tblStock![UnitCost] = Me.UnitCost.Value
tblStock![SalePrice] = Me.SalePrice.Value
tblStock![Margin] = Me.Margin.Value
tblStock![InventoryItem] = Me.MinStockSelect
tblStock![GSTApplicable] = Me.GSTApplicable.Value
tblStock![Active] = Me.Active.Value
tblStock.Update
If Me.MinStockSelect = True Then
Dim tblInvMins As DAO.Recordset
Dim LastestDate As TempVars
TempVars!LatestDate = DLookup("StockNumber", "tblStock", "LatestDate = #" _
& DMax("LatestDate", "tblStock") & "#")
Set tblInvMins = CurrentDb.OpenRecordset("SELECT * FROM [tblInvMins]")
tblInvMins.AddNew
tblInvMins![StockItem] = Me.StockItem
tblInvMins![StockNumber] = TempVars!LatestDate
tblInvMins![MinStock] = Me.MinStock
tblInvMins![OpeningStock] = Me.StockCount
tblInvMins![Supplier] = Me.Supplier
tblInvMins![SupplierId] = Me.SupplierId
tblInvMins.Update
End If
TempVars.RemoveAll
End Sub
I need to prevent the checkbox fields from creating a record until the entire form is completed.
Would appreciate any assistance on this
Thanks