/ Published in: VB.NET
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
Private Sub txtBarcode_AfterUpdate() If Nz(txtBarcode.Value) = "" Then MsgBox "Barcode is required...", vbExclamation, "Oops!" ElseIf DCount("Barcode", "tblInventoryInformation", "[Barcode]=" & Me.txtBarcode) > 0 Then MsgBox "This barcode already exists!", vbCritical, "Error!" txtBarcode.Value = Null Cancel = True End If End Sub Private Sub chkITRelated_AfterUpdate() Dim stDocName As String Dim stLinkCriteria As String Dim intAnswer As Integer Dim strSQL As String stDocName = "frmITRelated" stLinkCriteria = "[Barcode]=" & Me![txtBarcode] If Nz(txtBarcode.Value) = "" Then MsgBox "Barcode is required...", vbExclamation, "Oops!" chkITRelated.Value = False Me.txtBarcode.SetFocus If chkITRelated.Value = True Then If DCount("*", "tblITRelated", stLinkCriteria) = 0 Then intAnswer = MsgBox("The barcode was not found!" & vbCrLf & "Would you like to add it to the IT Related table now?", vbQuestion + vbYesNo, "Hello World!") If intAnswer = vbYes Then strSQL = "INSERT INTO tblITRelated([Barcode])" & "VALUES ([txtBarcode]);" DoCmd.SetWarnings False DoCmd.RunSQL strSQL DoCmd.SetWarnings True MsgBox "The barcode has been added!", vbInformation, "Great Success!" Response = acDataErrAdded DoCmd.OpenForm stDocName, , , stLinkCriteria ElseIf intAnswer = vbNo Then MsgBox "Clearing IT Related checkbox...", vbInformation, "Oh noes!" chkITRelated.Value = False Response = acDataErrContinue End If Else DoCmd.OpenForm stDocName, , , stLinkCriteria End If End If End If End Sub