473,419 Members | 1,815 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,419 software developers and data experts.

DMax function Problem

Hi,

I have a form called Customer based on the table tblCustomer and
another form called Job based on the table Job

when the user enter the details for the Customer i have a button at the bottm of the form called EnterJob where it directs to the Job Form

I have included some code in EnterJob button so when the user clicks, it gets the value for Customer Name and Max value of the Job number and enter into the appropriate field in the Job form.. Code is :

Private Sub EnterJobLabel_Click()

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

DoCmd.OpenForm "New_Job"
DoCmd.GoToRecord , , acNewRec

Forms!New_Job!Company_Name.Value = Forms!New_Customer!Company_Name.Value


Forms!New_Job!Job_No = DMax("Job_No", "CHS_Job") + 1

End Sub


I dont have problem to get the company name from the current form and palce it to the job form..
but i cant get the Max number for Job_No .
what i am getting is an empty field.

I think Dmax function works fine but it is not assigning the value into the Job_No field in Job Form

could anyone tell me what i have done wrong???

regards,
Catherine
Sep 5 '07 #1
2 3399
Hi,

I have a form called Customer based on the table tblCustomer and
another form called Job based on the table Job

when the user enter the details for the Customer i have a button at the bottm of the form called EnterJob where it directs to the Job Form

I have included some code in EnterJob button so when the user clicks, it gets the value for Customer Name and Max value of the Job number and enter into the appropriate field in the Job form.. Code is :

Private Sub EnterJobLabel_Click()

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

DoCmd.OpenForm "New_Job"
DoCmd.GoToRecord , , acNewRec

Forms!New_Job!Company_Name.Value = Forms!New_Customer!Company_Name.Value


Forms!New_Job!Job_No = DMax("Job_No", "CHS_Job") + 1

End Sub


I dont have problem to get the company name from the current form and palce it to the job form..
but i cant get the Max number for Job_No .
what i am getting is an empty field.

I think Dmax function works fine but it is not assigning the value into the Job_No field in Job Form

could anyone tell me what i have done wrong???

regards,
Catherine

Sorry guys.
I got that working...

i declared the field as Text .silly me...
only now i noticed it.

I changed it to number and its all working.. i would hav gone with autonumber but i want to get the max number through VBA

regards,
Catherine
Sep 5 '07 #2
Jim Doherty
897 Expert 512MB
Sorry guys.
I got that working...

i declared the field as Text .silly me...
only now i noticed it.

I changed it to number and its all working.. i would hav gone with autonumber but i want to get the max number through VBA

regards,
Catherine

Just an observation Catherine... if your db is used by you only then fine, but if you intend to use it in a multi user environment you might want to revisit the design on the way you are passing that value over?.

It is possible in a MU environment using that method, that 'someone else' will grab the number you have passed over statically to the job form and use it to insert a job before you had the chance to do so. Potentially when you come to applying the Dmax number you requested as a new record you'll get a 'Duplicates not allowed' message.

You might want to look at the BeforeInsert event of the Job form to grab the latest number for your job and base the Customer to whom it applies as the value of the 'Openargs' of the form?
where openargs 'value' is passed over to jobs form as part of the DoCmd.Openform arguments command...... from the customers form.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeInsert(Cancel As Integer)
  2. 'I'll leave you to do your own error handling here
  3. dim mynewnum as long
  4. mynewnum= DMax("[JobID]","YourJobTable","[CustomerID]='" & Me.OpenArgs &")
  5. Me!JobID=mynewnum
  6. Me!CustomerID=Me.Openargs
  7.  
  8. End sub
  9.  

Regards

Jim
Sep 5 '07 #3

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

Similar topics

3
by: Scott | last post by:
I have a database with an input form. The field "DailyID" on the form is to increment automatically with each new entry, then reset itself back to "1" at midnight and/or the change of date. ...
4
by: lukeargent | last post by:
Hi All, I have come across some rather weird error that I can only assume is something to do with my ADP file connecting to SQL Server 2000. I'm using Access XP as my front end. In simple...
3
by: Ron | last post by:
Hi All, Okay, here's the deal: Access2000/WinXP. Have a database that's split, FE/BE with multiple users having FE and one of those users also has BE (still split though...). Have a form on...
4
by: Ed Marzan | last post by:
Greetings, I have a query that returns varying prices for the same item in the following manner. Item1 Price1 Item1 Price2 Item1 Price3 Item1 Price4
4
by: jacc14 | last post by:
Hi This is the second query I have had with Dmax. The first one I resolved as it was in a form and by using DMAX everytime I click for new record it gave a new order number ie dmax("ordernumber",...
2
by: joeyrhyulz | last post by:
Hi, I'm trying to make a very simple update statement (in Oracle) in jet sql that seems much more difficult than it should be. The root of my problem is that I'm trying to update a field on a...
2
by: barmatt80 | last post by:
Ran into a problem, just as I thought I had it working. Dim strCurrentFiscalYear As String strCurrentFiscalYear = DLookup("", "YearReset", " = 1") Dim strLastFiscalYear As String ...
1
by: nrtyme | last post by:
Hello, I need to add several new records to Table2 from Table1. Table2 contains a field called that needs to be the previous maximum value of incremented by 1. Below is my code but i keep...
21
by: DanicaDear | last post by:
I have a report named "rptHOTSTICKS_EXPIRING" based on a query named "HOSTICKS_SHIPPING_REPORT Query". The query contains these fields: ORDER_NUM (text) CUST_NUM (text) Name, address, contact...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.