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 21334
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,534
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,534
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,534
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: Rina0 |
last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: lllomh |
last post by:
How does React native implement an English player?
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| |