Hello all,
I am trying to code a message box to display the record number of the record the user just added as a confirmation number. The user clicks on the message box to add the record and close out of the form. How do I retrieve the record number just added and display it?
Please e-mail me at: [email removed]
Here is the code for the button: -
-
Private Sub Add_Nomination_Click()
-
On Error GoTo Add_Nomination_Click_Err
-
-
Beep
-
MsgBox "Your nomination has been submitted. Thank you!", vbInformation, "Record Added"
-
DoCmd.Close acForm, "Nomination Form"
-
-
Add_Nomination_Click_Exit:
-
Exit Sub
-
-
Add_Nomination_Click_Err:
-
MsgBox Error$
-
Resume Add_Nomination_Click_Exit
-
-
End Sub
-
Thank you for your help!!!
7 21352
Hello all,
I am trying to code a message box to display the record number of the record the user just added as a confirmation number. The user clicks on the message box to add the record and close out of the form. How do I retrieve the record number just added and display it?
Please e-mail me at: [email removed]
Here is the code for the button: -
-
Private Sub Add_Nomination_Click()
-
On Error GoTo Add_Nomination_Click_Err
-
-
Beep
-
MsgBox "Your nomination has been submitted. Thank you!", vbInformation, "Record Added"
-
DoCmd.Close acForm, "Nomination Form"
-
-
Add_Nomination_Click_Exit:
-
Exit Sub
-
-
Add_Nomination_Click_Err:
-
MsgBox Error$
-
Resume Add_Nomination_Click_Exit
-
-
End Sub
-
Thank you for your help!!!
Do you want to retrieve a unique ID or the count of records?
NeoPa 32,556
Expert Mod 16PB
Please include the MetaData for all relevant datasets. Here is an example of how to post table MetaData : - Table Name=tblStudent
- Field; Type; IndexInfo
-
StudentID; Autonumber; PK
-
Family; String; FK
-
Name; String
-
University; String; FK
-
Mark; Numeric
-
LastLesson; Date/Time
MODERATOR
MetaData: - TableName = Nominations
-
NominationID; Autonumber; PK
-
Date of Nomination; Date/Time
-
Nominated Employee; Text; FK
-
Nominator; Text; FK
-
FishPrinciple; Text; FK
-
Reason For Recognition; Memo
This is a database for an employee recognition program... When a user submits a nomination, I would like them to receive the nominationID # (primary key) through the message box. I am going to create an additional form where users can go in, type in the primary key, and I will write a query to retrieve whether or not the reward has been given out which I will store in a separate table with NominationID as a foreign key. I am comfortable doing the rest - but I have no idea how to write the code to give the user the nomination ID for the record they just added!
Thanks so much.
NeoPa 32,556
Expert Mod 16PB
Nicely done with the MetaData Tania. You get the prize for being the first person, so far, to follow the format accurately :D
Funnily enough, there's no really accurate (direct) way of doing this unless you know something about how it works that would help to identify the record just entered.
I will assume, unless told otherwise, that the last record entered is the one required. DLast() may work in place of DMax() but it's hard for me to test that it will in all circumstances so it would be a good idea for you to test that to your satisfaction first. I include the code for using DLast() but commented out. Only use one of the lines in your final version. - Private Sub Add_Nomination_Click()
-
On Error GoTo Add_Nomination_Click_Err
-
Dim strMsg As String
-
-
'Code to add the record here
-
-
'strMsg = DLast([NominationID]", "[Nominations]")
-
strMsg = Mid(DMax("Format([Date of Nomination]," & _
-
"'yyyymmdd') & [NominationID]", _
-
"[Nominations]"), 9)
-
strMsg = Replace("Your nomination ([NominatinID]=%N) " & _
-
"has been submitted. Thank you!", _
-
"%N", strMsg)
-
Beep
-
Call MsgBox(strMsg, vbInformation, "Record Added")
-
Call DoCmd.Close(acForm, Me.Name)
-
-
Add_Nomination_Click_Exit:
-
Exit Sub
-
-
Add_Nomination_Click_Err:
-
MsgBox Error$
-
Resume Add_Nomination_Click_Exit
-
-
End Sub
Thank you! I took a database programming course in college and remember metadata vaguely! =)
Sorry for the extreme delay in my response - I will give the code a shot. Thanks soo much!
This works great!!!! I have to add 1 to the nomination ID the code pulls in, but this is just what I was looking for. Thank you so much! =)
Nicely done with the MetaData Tania. You get the prize for being the first person, so far, to follow the format accurately :D
Funnily enough, there's no really accurate (direct) way of doing this unless you know something about how it works that would help to identify the record just entered.
I will assume, unless told otherwise, that the last record entered is the one required. DLast() may work in place of DMax() but it's hard for me to test that it will in all circumstances so it would be a good idea for you to test that to your satisfaction first. I include the code for using DLast() but commented out. Only use one of the lines in your final version. - Private Sub Add_Nomination_Click()
-
On Error GoTo Add_Nomination_Click_Err
-
Dim strMsg As String
-
-
'Code to add the record here
-
-
'strMsg = DLast([NominationID]", "[Nominations]")
-
strMsg = Mid(DMax("Format([Date of Nomination]," & _
-
"'yyyymmdd') & [NominationID]", _
-
"[Nominations]"), 9)
-
strMsg = Replace("Your nomination ([NominatinID]=%N) " & _
-
"has been submitted. Thank you!", _
-
"%N", strMsg)
-
Beep
-
Call MsgBox(strMsg, vbInformation, "Record Added")
-
Call DoCmd.Close(acForm, Me.Name)
-
-
Add_Nomination_Click_Exit:
-
Exit Sub
-
-
Add_Nomination_Click_Err:
-
MsgBox Error$
-
Resume Add_Nomination_Click_Exit
-
-
End Sub
NeoPa 32,556
Expert Mod 16PB
You're very welcome Tania.
I can't believe I missed out adding one to the ID, but I'm glad you caught it anyway.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Sergio del Amo |
last post by:
Hi,
I implemented a Web-Site based in remote scripting with hidden frames. I
am using Javascript to provide dynamic functionality. In the machine's
local server works perfectly but when i uploaded...
|
by: Mike Ridley |
last post by:
I have just inherited an Access Booking Application. Works fine,
including some quite complex code that calculates an availability
table from dates input by the user.
I have produced a simple...
|
by: jamesbeswick |
last post by:
I've been using Access since version 97 and I've migrated to 2003. I've
noticed a substantial number of strange ActiveX/OLE and code corruption
problems when writing databases. The only solution...
|
by: Stephen E. Weber |
last post by:
I have an access database with an "item number" and a filespec for a JPG
with the image for the item and a filespec for a HTM document with the
description and specifications. I use a List Box and...
|
by: Ben |
last post by:
Hi,
i have some problem to access from code-behind a label nested into a
CreateWizard control. I use a html-table for align purpose only.
I try to change the text property of the label with...
|
by: jasperz01 |
last post by:
Hi,
Is it possible using Office Automation to freeze panes in Excel from Access VBA code? I've been trying some things but can't get it right...
Jasper
|
by: teddysnips |
last post by:
I have a new client who has an Access 2000 database that used to run
under Windows 2000 Pro. They have just "upgraded" to Access 2007
under Vista, and the old database stopped working - buttons on...
|
by: Bobby |
last post by:
Hi
Can anybody tell me why the VBA code below works fine in Access 2003
but doesn't work in Access 2007? I do not get any error message, even
if I put a deliberate error into the code. Also, if I...
|
by: Owen Jenkins |
last post by:
I have Access 97, 2000 and 2003 all running on a Win XP box after having
just reinstalled XP. Among other problems, I find that Access 97 will
not compact a database in code ...
...
|
by: JFKJr |
last post by:
I have an excel file, which has columns C and D grouped together, I am trying to delete blank columns and rows from the excel file, ungroup the columns and import the file to MS Access using Access...
|
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...
|
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...
|
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,...
|
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: 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,...
|
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...
|
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: 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 ...
| |