If else with dcount

hardik_088

Registered User.
Local time
Today, 16:46
Joined
May 31, 2011
Messages
82
hi guys,
I know here is my little mistake that i cannot find.
I want that if here description is same as table data then it should check part number if it is same then it should check location if it is same then it should check department,location and if same then i want to update query. From description,part number , department,location if any thing is diffrent then it should insert data.

There is no any mistacke in insert or update query just if else has mistake.
I tried but not working.Below is my code

----------
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("[part number]", "Laptops", "[Part number] = " & Chr(34) & Forms!Insert_data.[part number] & Chr(34)) > 0 Then
If DCount("[department]", "Laptops", "[department] = " & Chr(34) & Forms!Insert_data.[Department] & 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 ([Date],[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 (" & "#" & Forms!Insert_data![Date].Value & "#" & ", " & 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 a lot.
 
Hi
I think your problem is a lack of quotes.
You may like to try this
Code:
If DCount("Description", "Laptops", "Description = " & Chr(34) & Forms!Insert_data.Description & Chr(34) & ") > 0 Then
If DCount("[part number]", "Laptops", "[Part number] = " & Chr(34) & Forms!Insert_data.[part number] & Chr(34) & ") > 0 Then
If DCount("[department]", "Laptops", "[department] = " & Chr(34) & Forms!Insert_data.[Department] & Chr(34) & ") > 0 Then
 

Users who are viewing this thread

Back
Top Bottom