DCount Issue

  • Thread starter mattc66 via AccessMonster.com
  • Start date
M

mattc66 via AccessMonster.com

In the before Update Event I have the following Code.

If Not IsNull(Me.TagNum) Then
If DCount("TagNum", "tblPhysicalData", Me.TagNum) >= 1 Then
MsgBox "The Tag Number already exists.", vbOKOnly + vbInformation
End If
End If

Once the user enters a TAG Number before it records that number to the table
it checks the table to make sure it's not already input. I am having trouble
with the code. It tells me the TabNum already exists every time, when I know
it's not yet be entered.

Can someone see the error's in my code?

Matt
 
J

John Vinson

In the before Update Event I have the following Code.

If Not IsNull(Me.TagNum) Then
If DCount("TagNum", "tblPhysicalData", Me.TagNum) >= 1 Then
MsgBox "The Tag Number already exists.", vbOKOnly + vbInformation
End If
End If

Once the user enters a TAG Number before it records that number to the table
it checks the table to make sure it's not already input. I am having trouble
with the code. It tells me the TabNum already exists every time, when I know
it's not yet be entered.

Can someone see the error's in my code?

I can see one just for starters. The third argument of a DCount (or
any other domain function) should be a Text String which evaluates to
a valid SQL WHERE clause (without the word WHERE) as a criterion to
select which records to count.

Try

DCount("TagNum", "tblPhysicalData", "[TagNum] = " & Me.TagNum)

or if TagNum is of Text datatype

DCount("TagNum", "tblPhysicalData", "[TagNum] = '" & Me.TagNum & "'")


John W. Vinson[MVP]
 
M

mattc66 via AccessMonster.com

That works and If I want the cursor to go back the TagNum control what would
I type?

John said:
In the before Update Event I have the following Code.
[quoted text clipped - 10 lines]
Can someone see the error's in my code?

I can see one just for starters. The third argument of a DCount (or
any other domain function) should be a Text String which evaluates to
a valid SQL WHERE clause (without the word WHERE) as a criterion to
select which records to count.

Try

DCount("TagNum", "tblPhysicalData", "[TagNum] = " & Me.TagNum)

or if TagNum is of Text datatype

DCount("TagNum", "tblPhysicalData", "[TagNum] = '" & Me.TagNum & "'")

John W. Vinson[MVP]
 
M

missinglinq via AccessMonster.com

Cancel = True
That works and If I want the cursor to go back the TagNum control what would
I type?
[quoted text clipped - 16 lines]
John W. Vinson[MVP]

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via AccessMonster.com
 
J

John Vinson

That works and If I want the cursor to go back the TagNum control what would
I type?

I'm sorry, Matt, I've read that sentence several times and I cannot
make out what you're asking. "go back the TagNum control"....?


John W. Vinson[MVP]
 
M

missinglinq via AccessMonster.com

I think he means after it's ascertained that the TagNum entered already exits,
he wants focus to return to the TagNum control, perhaps to enter a different
TagNum. Hence, Cancel = True> It would help, of course, if we knew the entire
scenario.

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via AccessMonster.com
 
J

John Vinson

I think he means after it's ascertained that the TagNum entered already exits,
he wants focus to return to the TagNum control, perhaps to enter a different
TagNum. Hence, Cancel = True> It would help, of course, if we knew the entire
scenario.

ah. Thanks, Linq.

(btw... I had to shield the screen so KalliCat in my lap didn't see
your .sig, she'd be MOST offended... <g>)

John W. Vinson[MVP]
 
M

missinglinq via AccessMonster.com

John, I often work with the head of my friend in my lap, and he always grins
when he sees it...'course he's Puck the Magic Chowhound, a 100 # black lab!

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via AccessMonster.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top