A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Database Design
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Dcount Question



 
 
Thread Tools Display Modes
  #1  
Old April 30th, 2007, 09:20 PM posted to microsoft.public.access.tablesdbdesign
bbcombo
external usenet poster
 
Posts: 3
Default Dcount Question

I am trying to use this code to count records and if the record is
found,"Your Data was entered". If no record is found I am trying to give
"Your Part Number was not found" and not enter the data. Here is my current
code, what corrections do I need to make? thanks in advance.
Private Sub PartNum_AfterUpdate()
Dim PartNum As String
Me.PartNum = PartNumber
x = DCount("[FootSwitch1]", "[Part Number Master]")
If x = 0 Then
MsgBox ("Your Data Was Entered")
Else: MsgBox ("Your Part Number Was Not Found")
End If

End Sub

  #2  
Old April 30th, 2007, 10:28 PM posted to microsoft.public.access.tablesdbdesign
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Dcount Question

On Mon, 30 Apr 2007 13:20:02 -0700, bbcombo
wrote:

I am trying to use this code to count records and if the record is
found,"Your Data was entered". If no record is found I am trying to give
"Your Part Number was not found" and not enter the data. Here is my current
code, what corrections do I need to make? thanks in advance.
Private Sub PartNum_AfterUpdate()
Dim PartNum As String
Me.PartNum = PartNumber
x = DCount("[FootSwitch1]", "[Part Number Master]")
If x = 0 Then
MsgBox ("Your Data Was Entered")
Else: MsgBox ("Your Part Number Was Not Found")
End If


Well, the short answer is that your DCount isn't counting what you think it's
counting. It's counting the number of records in the table named [Part Number
Master] which have a non-NULL value in the field FootSwitch1. There might be
dozens or hundreds, and in any case the DCount will not make any reference to
what the user has entered. You'll need to use the (optional) third argument to
search the appropriate field (which I do not know!) in [Part Number Master].

BUT... rather than making users type a part number, and slapping their hands
if they type wrong, why not use a Combo Box based on the [Part Number Master]
table? Then the user can *select* (typing into the combo box with autocomplete
makes this really fast) a valid value.

John W. Vinson [MVP]
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 04:51 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.