473,385 Members | 1,582 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Daily Number and Date

79 64KB
Hi,

I am trying to build a date coding system in Access. A set of number is automatically generated on daily basis started from 1 everyday. These data are stored in a table call T_Job with following fields.

Job_ID
Production_Date
Recipe_ID
Recipe_Ver
QTY
UOM
DailyNumber

In the active form, I have a text box named txtProductionDate that user can enter production date. The date value from this text box is then passed to a vba variable called ProdDate.

In the vba, I tried this code just to see if this approach works.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim ProdDate As Date
  3.  
  4. ProdDate = Me.[txtProductionDate].Value
  5.  
  6. MsgBox Nz(DMax("[DailyNumber]", "[T_Job]", Production_Date = ProdDate), 0), vbOKOnly
  7.  
However, the message box always return 0 perhaps the DailyNumber is constantly being null.

On the other hand, when I tried the code in the Immediate panel below the vba editor, the message box returns correct number.

Can anyone tell me what went wrong with the code?

Thanks,
Joe
Jun 23 '16 #1

✓ answered by PhilOfWalton

Try

Expand|Select|Wrap|Line Numbers
  1.  
  2. MsgBox Nz(DMax("[DailyNumber]", "[T_Job]", 
  3. "Production_Date = #" & ProdDate) & "#", 0), vbOKOnly
  4.  
There are 2 problems with your code
1) The Where condition needs quotes("") round it.
2) Date comparisons need a Hash (#) on either side of the date.

Although not relevant to your current question, Text comparisons need quotes round them, but this tends to behard to read so I use Chr$(34) instead.

5 1210
PhilOfWalton
1,430 Expert 1GB
Try

Expand|Select|Wrap|Line Numbers
  1.  
  2. MsgBox Nz(DMax("[DailyNumber]", "[T_Job]", 
  3. "Production_Date = #" & ProdDate) & "#", 0), vbOKOnly
  4.  
There are 2 problems with your code
1) The Where condition needs quotes("") round it.
2) Date comparisons need a Hash (#) on either side of the date.

Although not relevant to your current question, Text comparisons need quotes round them, but this tends to behard to read so I use Chr$(34) instead.
Jun 23 '16 #2
jforbes
1,107 Expert 1GB
I would recommend putting Option Explicit at the top of your code modules. Having Option Explicit turned on would have pointed out that "Production_Date" was an undefined variable.
Jun 24 '16 #3
Joe Y
79 64KB
Phil,

Adding # on either side of date comparison works. I had to make small format changes from your code, but it works!

Many thanks.
Joe
Jun 24 '16 #4
NeoPa
32,556 Expert Mod 16PB
Phil:
Date comparisons need a Hash (#) on either side of the date.
Hi Phil.

I would advise caution when giving advice about date formatting in SQL. It really isn't as simple as adding hashes (#) around a date string formatted in the default way by Access (See Literal DateTimes and Their Delimiters (#)). This is a particular problem as it will seem to work in most cases because Jet/ACE does some automatic recognition of the string so only those which can be ambiguous are ever seen to fail. It is quite important to mention that the date needs to be formatted in one of the specified ways in order for it to be reliable.

JForbes:
Having Option Explicit turned on would have pointed out that "Production_Date" was an undefined variable.
I would never argue against that J, but in this case I believe "Production_Date" was intended to be a reference to a field rather than a VBA variable. The OP forgot to add the quotes which would have made it all clearer.
Jun 26 '16 #5
zmbd
5,501 Expert Mod 4TB
This question appears to be a variation on the theme:
home > topics > microsoft access / vba > insights > item numbering within a group .

Of course, this article references a yearly cycle; however, with a few modifications it should be useable for daily cycles. I haven't reviewed the article's code for such usage; however, if OP desires we can work thru that here.

-Z
Jun 27 '16 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Sven Mayer | last post by:
Assume a database (e.g. Oracle) field is declared as a) NUMBER (length=10) b) NUMBER (length=26) c) VARCHAR2 (length=1) d) VARCHAR2 (length=50) e) DATE How do I retrieve the contents from...
3
by: Bob Sanderson | last post by:
I need to add a number of months to a date field to derive a new date field. I can get the addition to work but it adds the number in days instead of months. In the example below, I want to add...
13
by: jm | last post by:
I am trying to use datepart to get the real name of the month like "April" or "APR" not just "4." I could not find it in the documentation. Sorry. Thank you.
1
by: Odie | last post by:
The date add feature is accessed through Queries and build.
4
by: CDMAPoster | last post by:
I'm starting to come up with a version of DateAdd that I call BusinessDateAdd that adds the selected number of business days. It's still in preliminary form (needs testing) and interacts with my...
4
by: IsdWeb | last post by:
Hello, I am a newbie to coding and need some help. I am trying to figure out why the following code is not producing the correct Julian date. Any suggestions? Also, I am trying to understand...
0
by: mwalsh62 | last post by:
Greetings all! My first post here, and my mind is pudding at this point (any flavor you like)! I have been searching for days, and still can't figure out the proper syntax that I require. This...
2
by: beaudreaux | last post by:
I have a report that is grouped by Quarter and have the following to give me a daily running average and to break/reset each quarter. However, the daily runnning average does not reset after the end...
7
by: Alex T | last post by:
I have made a date program. I need it to do three things now: 1. Return the previous dates, (0, 1, 2, 3... Days ago) 2. Skip the weekends. 3. Skip these holidays: New Year's Day (Jan 1) MLKJ...
1
by: bretdunlap | last post by:
Hi I need an example of a gym or club/martial-art attendance database. what I want to do is type in a code for a member and his or her attendance is recorder on a table as a date. So that a t a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.