Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use DCount??

Status
Not open for further replies.

marlun

Programmer
Feb 7, 2003
70
SE
Hi there!
I have vb-code that searches for duplicate records:

If DCount("ProdSN", "Lager", "ProdSN = '" & Me!ProdSN & "'") > 0 And _
DCount("ProjIn", "Lager", "ProjIn = '" & Me!ProjIn & "'") > 0 Then

The problem I have is that it counts matching field on different rows in the table "Lager". I want it to find "ProdSN" and "ProjIn" where they exist on the same row in the table table.

I'm pretty fresh at vb-coding, perhaps there are a better ways to find duplicates. Would appreciate any help =D

Hope my english isn't to bad for you to understand

Thanks
 
You're so close. I think you just need to AND together the two WHERE statements.

If DCount("ProdSN", "Lager", "ProdSN = '" & Me!ProdSN & "'") > 0 And _
DCount("ProjIn", "Lager", "ProjIn = '" & Me!ProjIn & "'") > 0 Then

becomes

If DCount("ProdSN", "Lager", "ProdSN = '" & Me!ProdSN & "' And ProjIn = '" & Me!ProjIn & "'") > 0 Then


Do you know those single quotes are only needed if the field value is a text string. Unneccessary for numeric values.
 
Thanks it worked perfectly, now I have another question. When (If DCount("ProdSN", "tblLager", "ProdSN = '" & Me!ProdSN & "' And ProjIn = '" & Me!ProjIn & "'") > 0 Then)
is true (>0) i want "it" to run an update query.
I have a field "Amount1" that I want to update. I want it to add the current Amount1 with an Amount2 i filled in a form. But it gives me a weird answer. If the current Amount is 5, and I add one, then the answer is 9. This is how my update-query looks like:

Field: Amount ProjIn ProdSN
Table: tblLager tblLager tblLager
^
Update to:[Amount1]+[Forms]![frmInLev]![Amount2]

Criteria: [Forms]![frmInLev]![ProjIn] And [Forms]![frmInLev]![ProdSN]

Hope you understand my query.

thanks

/marlun
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top