Wrox Programmer Forums
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old March 1st, 2007, 04:33 AM
Friend of Wrox
Join Date: Apr 2006
Posts: 159
Thanks: 0
Thanked 0 Times in 0 Posts
Default DCount problem using vba


Have another problem I can't seem to solve.

What I am trying to do is to get the number of values (so dcount I guess) for a given criteria to show up in a text box.

I am trying to use the next dcount, but it isn't working...

Private Sub Form_Load()

Me.PtagYes.Value = DCount("[tblTestBuyBA01]![Ptag]", "tblTestBuyBA01", "[tblTestBuyBA01]![Ptag] = Ja/Oui And [tblTestBuyBA01]![Invoerdatum] >= [Forms]![frmPercentTestBuyIntermediate]![Begindatum] And [tblTestBuyBA01]![Invoerdatum] <= [Forms]![frmPercentTestBuyIntermediate]![Einddatum]")

End Sub

The number of values that has to be returned should be displayed, but the text box remains empty when the form opens. I also tried to put the =Dcount... in the text box control source,but this isn't working either...

any one have an idea? Maybe my function is just wrong somewhere...

Old March 30th, 2007, 02:26 PM
Friend of Wrox
Join Date: Feb 2007
Posts: 163
Thanks: 0
Thanked 2 Times in 2 Posts

hmm.... what is Ja/Oui? Field values from the table? Or is it supposed to be a string literal?

The way it reads right now, you're dividing Ja by Oui for what Ptag should be.
Is the form the field is on named frmPercentTestBuyIntermediate? Should Einddatum be Enddatum?

Assuming that Ja/Oui is a string literal the content in the string field Ptag must match, correcting Einddatum spelling, and that the form referenced IS the form this object is on, I'd try:
=DCount("Ptag","tblTestBuyBA01","Ptag = 'Ja/Oui' And Invoerdatum >= Begindatum And Invoerdatum <= Enddatum")

Notice that since it's a string literal I put Ja/Oui between ' marks. I built a test with these values and field names and it worked.

You may also want to code a refresh for your text box when values in BeginDatum, Invoerdatum, Enddatum or Ptag are changed.

Does this help?

Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with VBA code.. need help arian29 VB Databases Basics 1 November 29th, 2008 07:44 PM
VBA to Outlook problem d12774 Access VBA 0 June 12th, 2007 03:04 PM
Dcount with local disconnected recordset DreamEagl Access VBA 7 March 10th, 2006 01:44 PM
VBA Editor problem dlamarche Access 4 February 22nd, 2005 10:19 AM
DCOUNT Issue - MS Access 97 snoopy92211 Access VBA 1 October 12th, 2004 02:38 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.