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 » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Recipe form



 
 
Thread Tools Display Modes
  #11  
Old February 5th, 2010, 01:32 AM posted to microsoft.public.access.forms
DF59
external usenet poster
 
Posts: 10
Default Recipe form

Thank you, perfect. Code wokred beautifully

"John W. Vinson" wrote in message
...
On Wed, 3 Feb 2010 18:45:01 -0500, "DF59" wrote:

ok, my conrolname is CatCount and the field names of my Recipes table ar
as
follows:


1) RecipeID Autonumber
2) CatCount Number
3) RecipeName Text
4) RecieDescription Text
5) FoodCategoryID Number
6) TimetoPrepare Text
7) CookTime Text
8) NumberofServings Number
9) Ingredients Memo
10) Instructions Memo
11) BookIncluded YesNo
12) Picture Ole Object
If I read John's last reply correctly, my code should look something like
this:

Me!CatCount = Count(CatCount = Tables!Recipes!{FoodCategoryID] ) + 1

I tried a setval macro to do this but the objects were not resolved
correctly.


There are a few ways to do this, but I'd suggest using VBA code, not a
Macro;
for a one-user system (where you won't have different users competing for
new
ID numbers) you could use the AfterUpdate event of the FoodCategoryID
combo
box. View its Properties; on the After Event property on the Events tab
click
the ... icon and choose Code Builder. Edit the code to

Private Sub FoodCategoryID_AfterUpdate
Me!CatCount = NZ(DMax("CatCount", "Recipes", _
"FoodCategoryID = " & Me!FoodCategoryID)) + 1
End Sub

This will look up the largest existing CatCount for this food category
(and
get a 0 if there aren't any yet); add 1, and store the result in the
CatCount
field. I like this better than counting records because that count will be
off
if you should ever delete a recipe.
--

John W. Vinson [MVP]



  #12  
Old February 5th, 2010, 04:11 AM posted to microsoft.public.access.forms
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Recipe form

On Thu, 4 Feb 2010 20:32:47 -0500, "DF59" wrote:

Thank you, perfect. Code wokred beautifully


Glad to have been of help. Payment in the form of a good vegetarian recipe
would be welcome... g
--

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 12:53 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.