I have a database with 4 tables: tblMembers, tblRides, Session table and Reservation table. One of the fields in the Members table is set to number, but now I have all relationships set up and the data inserted, but one problem is now that when I add a new user it doesn't increment.. Is there any way with VBA, that I can grab the last CustomerID from the table and add one to it, and insert that as the new ID?
I was thinking to grab the last CustomerID of using -
Dim SQL As String
-
-
SQL = "SELECT CustomerID FROM tblMembers ORDER BY CustomerID DESC;"
-
-
DoCmd.RunSQL SQL
That would simply get the value... the part of using it as a new ID may be doable with an INSERT INTO query.
how would I then increment the value from the query by one?
Sam
Jan 15 '08
14 8971 Rabbit 12,516
Recognized Expert Moderator MVP
I'm just wondering why in the form you're using CustID but in the DMax you're using CustomerID. Should they not be the same? Aside from that, the code should work fine.
CustID is the name of the control on the form. CustomerID is the name of the field in the table. Despite the fact that Access will name the control the same as the field, if you drag the field from the Field List Box to the form, many experts believe it's good policy to change the name of the control to something different. There are times when Access will get confused if they're both the same.
And yeah, the code is tested and functions fine.
Linq ;0)> Rabbit 12,516
Recognized Expert Moderator MVP CustID is the name of the control on the form. CustomerID is the name of the field in the table. Despite the fact that Access will name the control the same as the field, if you drag the field from the Field List Box to the form, many experts believe it's good policy to change the name of the control to something different. There are times when Access will get confused if they're both the same.
And yeah, the code is tested and functions fine.
Linq ;0)>
I see. If I do that, which is rare because I'm lazy, I like to prefix it with a control identifier like txt or lbl.
sierra7 446
Recognized Expert Contributor
Hi
If I want to 'pad-out' a value with zeros, say next CustID = 1234 (a number) but I want 0001234 I suggest;- -
Dim CMax as Long
-
-
CMax = Nz(DMax("[CustomerID]","tblMembers"),0) + 1
-
-
Me!CustID = Right((100000000 + CMax), 7)
I would probably write it in one line without using CMax but t's easier to read like this.
When using a Dynamic Lookup function I usually check that the field name bit, [CustomerID], has square brackets around even if it hasn't spaces in it.
S7
Not better way to start a Wednesday at work than with a happy dance. It works perfectly! Thanks for all the help!
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Irwinsp |
last post by:
Hi All,
I have a form with an auto number field displayed. The field looks great
except when the user is entering a new record. The field then has the text
"auto number" in it. Is there a better way to display this field. I thought
the number assigned to this record should be displayed while the user is
entering the rest of the form data.
Thanks,
Paula
|
by: Geoff Cayzer |
last post by:
At http://www.blueclaw-db.com/tips_tricks.htm I came across a section
which is included below and was hoping for some comment on the
article.
--------------
Almost never use this auto-number field as the primary key of the
table.
If you are thinking of hiring an Access programmer or consultant ask
|
by: Vikaspell |
last post by:
I want to set a auto number but the first 3 digits should be picked
from a value of another table like for example a customer no is 999
i want the Pet no of this customer to be 999/(Autonumber)
i can i get this done
what i want is no user input in this field
user will select the customer from the otrher table which give the
first 3 digits and the auto number should come on it own
|
by: John Baker |
last post by:
Hi:
I know this is a strange question, but I have inherited a system where files are copied
and records re auto numbered (as an index field) )frequently, and I am wondering how high
the number can go without the system crashing.
An ancillary question is how one resets an auto number so that the sequence starts again
at 1.
In the case of this file, the auto number field serves no useful purpose except as an
|
by: the hotshot |
last post by:
hello,
this seems to be a hard question so far and noone has been able to help
with this. is it possible to have access start an autonumber with a
prefix according to the year when the data is entered. for example, if
i entered something in 2004, i would like the number to bigin with
2004003, 2004004, 2004005... and same for 2005001, 2005002...?
much and great appreciation for suggestions.
thank you,
| |
by: John Phelan-Cummings |
last post by:
I'm not certain if this made the post. Sorry if it's a repeat:
Using a Button to take an autonumber from one form to populate another
autonumber field on another form.
I have a Mainform "A" with a button and code that opens another Mainform
"B"
with a subform which has the same table as Mainform "A".
The button is supposed to tell the subform with the autonumber field
|
by: S.Dickson |
last post by:
I had an access database that i use as an ordering system. I have a
form for entering customer details. When i add a new customer on the
form the customer number is an auto number that appears when i type in
the details.
I have just moved over to mysql server with access as the front end. I
have setup the sql tables with the customer number as autonumber.
When i go into the form and add a new customer it does not generate the
|
by: asandiego |
last post by:
Hey guys, this is my first post here but have been checking this site a lot for anything I need.
I hope someone can lead me to what I should do or just an idea to what can be done.
What I'm trying to do:
I have a Form that has a subform. My primary form has a field that autonumber and this field has a one to many relationship to a field in my subform.
The subform has another field that I want to AutoNumber or increment number BUT has to go...
|
by: jinalpatel |
last post by:
I am dealing with 3 tables. Here is a brief meta data
see the attachment for the relationship
Conditions:
1)One GrantIndex can have multiple Deliverables
2)one Deliverable is made from combination of more than 85 performance measures.
Performance measures have chkbox value, textbox value (number) and goal value(number)
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |