472,782 Members | 1,273 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

access message box/ VB code.

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:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Add_Nomination_Click()
  3. On Error GoTo Add_Nomination_Click_Err
  4.  
  5.     Beep
  6.     MsgBox "Your nomination has been submitted. Thank you!", vbInformation, "Record Added"
  7.     DoCmd.Close acForm, "Nomination Form"
  8.  
  9. Add_Nomination_Click_Exit:
  10.     Exit Sub
  11.  
  12. Add_Nomination_Click_Err:
  13.     MsgBox Error$
  14.     Resume Add_Nomination_Click_Exit
  15.  
  16. End Sub
  17.  


Thank you for your help!!!
Feb 15 '07 #1
7 21334
MMcCarthy
14,534 Expert Mod 8TB
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:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Add_Nomination_Click()
  3. On Error GoTo Add_Nomination_Click_Err
  4.  
  5.     Beep
  6.     MsgBox "Your nomination has been submitted. Thank you!", vbInformation, "Record Added"
  7.     DoCmd.Close acForm, "Nomination Form"
  8.  
  9. Add_Nomination_Click_Exit:
  10.     Exit Sub
  11.  
  12. Add_Nomination_Click_Err:
  13.     MsgBox Error$
  14.     Resume Add_Nomination_Click_Exit
  15.  
  16. End Sub
  17.  


Thank you for your help!!!
Do you want to retrieve a unique ID or the count of records?
Feb 15 '07 #2
NeoPa
32,534 Expert Mod 16PB
Please include the MetaData for all relevant datasets. Here is an example of how to post table MetaData :
Expand|Select|Wrap|Line Numbers
  1. Table Name=tblStudent
  2. Field; Type; IndexInfo
  3. StudentID; Autonumber; PK
  4. Family; String; FK
  5. Name; String
  6. University; String; FK
  7. Mark; Numeric
  8. LastLesson; Date/Time
MODERATOR
Feb 16 '07 #3
MetaData:
Expand|Select|Wrap|Line Numbers
  1. TableName = Nominations
  2. NominationID; Autonumber; PK
  3. Date of Nomination; Date/Time
  4. Nominated Employee; Text; FK
  5. Nominator; Text; FK
  6. FishPrinciple; Text; FK
  7. 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.
Feb 16 '07 #4
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.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Add_Nomination_Click()
  2. On Error GoTo Add_Nomination_Click_Err
  3.     Dim strMsg As String
  4.  
  5.     'Code to add the record here
  6.  
  7.     'strMsg = DLast([NominationID]", "[Nominations]")
  8.     strMsg = Mid(DMax("Format([Date of Nomination]," & _
  9.                       "'yyyymmdd') & [NominationID]", _
  10.                       "[Nominations]"), 9)
  11.     strMsg = Replace("Your nomination ([NominatinID]=%N) " & _
  12.                      "has been submitted. Thank you!", _
  13.                      "%N", strMsg)
  14.     Beep
  15.     Call MsgBox(strMsg, vbInformation, "Record Added")
  16.     Call DoCmd.Close(acForm, Me.Name)
  17.  
  18. Add_Nomination_Click_Exit:
  19.     Exit Sub
  20.  
  21. Add_Nomination_Click_Err:
  22.     MsgBox Error$
  23.     Resume Add_Nomination_Click_Exit
  24.  
  25. End Sub
Feb 17 '07 #5
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!
Mar 23 '07 #6
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.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Add_Nomination_Click()
  2. On Error GoTo Add_Nomination_Click_Err
  3.     Dim strMsg As String
  4.  
  5.     'Code to add the record here
  6.  
  7.     'strMsg = DLast([NominationID]", "[Nominations]")
  8.     strMsg = Mid(DMax("Format([Date of Nomination]," & _
  9.                       "'yyyymmdd') & [NominationID]", _
  10.                       "[Nominations]"), 9)
  11.     strMsg = Replace("Your nomination ([NominatinID]=%N) " & _
  12.                      "has been submitted. Thank you!", _
  13.                      "%N", strMsg)
  14.     Beep
  15.     Call MsgBox(strMsg, vbInformation, "Record Added")
  16.     Call DoCmd.Close(acForm, Me.Name)
  17.  
  18. Add_Nomination_Click_Exit:
  19.     Exit Sub
  20.  
  21. Add_Nomination_Click_Err:
  22.     MsgBox Error$
  23.     Resume Add_Nomination_Click_Exit
  24.  
  25. End Sub
Mar 23 '07 #7
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.
Mar 24 '07 #8

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

Similar topics

2
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...
1
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...
26
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...
2
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...
4
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...
5
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
1
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...
3
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...
5
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 ... ...
0
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...
0
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...
3
isladogs
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...
0
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...
14
DJRhino1175
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...
0
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...
5
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...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
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...

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.