hardik_088
Registered User.
- Local time
- Yesterday, 16:32
- Joined
- May 31, 2011
- Messages
- 82
hi guys,
i have laptops form and that has description,[quantity ordered],location,[suggested supplier] ,[part number] fields and i have form "Insert_data" that have textbox and i want to insert data and also want to check this fields descritption,[suggested supplier],[quantity ordered],[part number],location and if same data is there in table then it should update otherwise insert new data and i have tried following code but when it is checking fields it is checking just description field and updating or inserting data So what i should do to check that fields.
If (Forms!Insert_Data![Type].Value = "Laptops") Then
If DCount("Description", "Laptops", "Description = " & Chr(34) & Forms!Insert_Data.Description & Chr(34)) > 0 Then
If DCount("Location", "Laptops", "Location = " & Chr(34) & Forms!Insert_Data.Location & Chr(34)) > 0 Then
If DCount("[part number]", "Laptops", "[part number] = " & Chr(34) & Forms!Insert_Data.[part number] & Chr(34)) > 0 Then
DoCmd.RunSQL "UPDATE Laptops SET Laptops.[quantity ordered] = Laptops.[quantity ordered] + " & Forms!Insert_Data![quantity ordered] & " WHERE Laptops.Description = " & Chr(34) & Forms!Insert_Data.Description & Chr(34)
DoCmd.Close acForm, "Insert_Data"
End If
End If
Else
DoCmd.RunSQL "INSERT INTO Laptops ([requsition type],[type],[purchase requisition],Location,department,requestor,[suggested supplier],[quantity ordered],[part number] ,Description,[privincial tracking number],[po number],[status],[billing code],[itscc code],[itscc task number]) " & _
" VALUES (" & Chr(34) & Forms!Insert_Data![requsition type].Value & Chr(34) & "," & Chr(34) & Forms!Insert_Data![Type].Value & Chr(34) & "," & Chr(34) & Forms!Insert_Data![purchase requisition].Value & Chr(34) & "," & Chr(34) & Forms!Insert_Data!Location.Value & Chr(34) & ", " & Chr(34) & Forms!Insert_Data![Department].Value & Chr(34) & "," & Chr(34) & Forms!Insert_Data!Supplier.Value & Chr(34) & "," & Chr(34) & Forms!Insert_Data![Requestor].Value & Chr(34) & "," & Forms!Insert_Data![quantity ordered].Value & "," & Chr(34) & Forms!Insert_Data![part number].Value & Chr(34) & "," & Chr(34) & Forms!Insert_Data!Description.Value & Chr(34) & ", " & _
" " & Chr(34) & Forms!Insert_Data![privincial tracking number].Value & Chr(34) & "," & Chr(34) & Forms!Insert_Data![po number].Value & Chr(34) & "," & Chr(34) & Forms!Insert_Data![Status].Value & Chr(34) & "," & Chr(34) & Forms!Insert_Data![billing code].Value & Chr(34) & "," & Chr(34) & Forms!Insert_Data![itscc code].Value & Chr(34) & "," & Chr(34) & Forms!Insert_Data![itscc task number].Value & Chr(34) & ")"
End If
Thanks you very much
i have laptops form and that has description,[quantity ordered],location,[suggested supplier] ,[part number] fields and i have form "Insert_data" that have textbox and i want to insert data and also want to check this fields descritption,[suggested supplier],[quantity ordered],[part number],location and if same data is there in table then it should update otherwise insert new data and i have tried following code but when it is checking fields it is checking just description field and updating or inserting data So what i should do to check that fields.
If (Forms!Insert_Data![Type].Value = "Laptops") Then
If DCount("Description", "Laptops", "Description = " & Chr(34) & Forms!Insert_Data.Description & Chr(34)) > 0 Then
If DCount("Location", "Laptops", "Location = " & Chr(34) & Forms!Insert_Data.Location & Chr(34)) > 0 Then
If DCount("[part number]", "Laptops", "[part number] = " & Chr(34) & Forms!Insert_Data.[part number] & Chr(34)) > 0 Then
DoCmd.RunSQL "UPDATE Laptops SET Laptops.[quantity ordered] = Laptops.[quantity ordered] + " & Forms!Insert_Data![quantity ordered] & " WHERE Laptops.Description = " & Chr(34) & Forms!Insert_Data.Description & Chr(34)
DoCmd.Close acForm, "Insert_Data"
End If
End If
Else
DoCmd.RunSQL "INSERT INTO Laptops ([requsition type],[type],[purchase requisition],Location,department,requestor,[suggested supplier],[quantity ordered],[part number] ,Description,[privincial tracking number],[po number],[status],[billing code],[itscc code],[itscc task number]) " & _
" VALUES (" & Chr(34) & Forms!Insert_Data![requsition type].Value & Chr(34) & "," & Chr(34) & Forms!Insert_Data![Type].Value & Chr(34) & "," & Chr(34) & Forms!Insert_Data![purchase requisition].Value & Chr(34) & "," & Chr(34) & Forms!Insert_Data!Location.Value & Chr(34) & ", " & Chr(34) & Forms!Insert_Data![Department].Value & Chr(34) & "," & Chr(34) & Forms!Insert_Data!Supplier.Value & Chr(34) & "," & Chr(34) & Forms!Insert_Data![Requestor].Value & Chr(34) & "," & Forms!Insert_Data![quantity ordered].Value & "," & Chr(34) & Forms!Insert_Data![part number].Value & Chr(34) & "," & Chr(34) & Forms!Insert_Data!Description.Value & Chr(34) & ", " & _
" " & Chr(34) & Forms!Insert_Data![privincial tracking number].Value & Chr(34) & "," & Chr(34) & Forms!Insert_Data![po number].Value & Chr(34) & "," & Chr(34) & Forms!Insert_Data![Status].Value & Chr(34) & "," & Chr(34) & Forms!Insert_Data![billing code].Value & Chr(34) & "," & Chr(34) & Forms!Insert_Data![itscc code].Value & Chr(34) & "," & Chr(34) & Forms!Insert_Data![itscc task number].Value & Chr(34) & ")"
End If
Thanks you very much