-MS Access 2002-
Im trying to create a form called 'update tool' that will take the values, Employee (number), Serial (text), Size (number), and compare the serial field of the form 'update tool' to a table that holds all of the serials, 'Tools'. So what i have for the 'on click' property of a Save command button is:
Dim strSQL1 As String
Dim strSQL3 As String
Dim stDocName As String
Dim stDocName1 As String
Dim intAnswer As Integer
Dim intAnswer1 As Integer
stDocName = "Tool Update"
stDocName1 = "add tool"
strSQL1 = "SELECT [Tools].Serial FROM [Tools] WHERE ([Tools].Serial = Forms![update tool]![Serial])"
strSQL3 = "INSERT INTO [Tools] (Serial, Size, LastUpdate, Status, Regrinder) VALUES (Forms![update tool]![Serial], Forms![update tool]![Size], Now, 'In', Forms![update tool].[Regrinder]);"
If (Not IsNull(strSQL1) = True) Then
intAnswer = MsgBox("Record not found, is this a new tool?", vbYesNo, "New Tool")
If (intAnswer = 6) Then
DoCmd.OpenQuery stDocName1, acNormal, acAdd
Else
MsgBox ("The tool was not found in the records, and was not added to inventory.")
Forms![update tool]![Regrinder] = Null
Forms![update tool]![Serial] = Null
Forms![update tool]![Size] = Null
End If
End If
So you can see what i'm trying to do, is compare if the serial already exists in the table, if it doesn't then prompt the user that no record was found and that it might be new. if it is new then it will be appened to the table 'tools'. if the record exists then the old record will be updated to the new information. Now i know that the first 'if' loop is wrong since the SQL i am using isn't giving the information i think i need. But what i am asking is how could i compare to see if the field 'serial' from the form already exists in a field 'serial' from a table, 'tools'?
Thanks for the help in advance
Im trying to create a form called 'update tool' that will take the values, Employee (number), Serial (text), Size (number), and compare the serial field of the form 'update tool' to a table that holds all of the serials, 'Tools'. So what i have for the 'on click' property of a Save command button is:
Dim strSQL1 As String
Dim strSQL3 As String
Dim stDocName As String
Dim stDocName1 As String
Dim intAnswer As Integer
Dim intAnswer1 As Integer
stDocName = "Tool Update"
stDocName1 = "add tool"
strSQL1 = "SELECT [Tools].Serial FROM [Tools] WHERE ([Tools].Serial = Forms![update tool]![Serial])"
strSQL3 = "INSERT INTO [Tools] (Serial, Size, LastUpdate, Status, Regrinder) VALUES (Forms![update tool]![Serial], Forms![update tool]![Size], Now, 'In', Forms![update tool].[Regrinder]);"
If (Not IsNull(strSQL1) = True) Then
intAnswer = MsgBox("Record not found, is this a new tool?", vbYesNo, "New Tool")
If (intAnswer = 6) Then
DoCmd.OpenQuery stDocName1, acNormal, acAdd
Else
MsgBox ("The tool was not found in the records, and was not added to inventory.")
Forms![update tool]![Regrinder] = Null
Forms![update tool]![Serial] = Null
Forms![update tool]![Size] = Null
End If
End If
So you can see what i'm trying to do, is compare if the serial already exists in the table, if it doesn't then prompt the user that no record was found and that it might be new. if it is new then it will be appened to the table 'tools'. if the record exists then the old record will be updated to the new information. Now i know that the first 'if' loop is wrong since the SQL i am using isn't giving the information i think i need. But what i am asking is how could i compare to see if the field 'serial' from the form already exists in a field 'serial' from a table, 'tools'?
Thanks for the help in advance