473,464 Members | 1,476 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 21352
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,556 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,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.
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,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.
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: 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
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...
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
jinu1996
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...
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.