954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

retrieving current record in database

hello, i neeed help badly.my problem is i want to retrieve the record that has just been added.
let say:
step :load RESERVATION form->fill in details->click the save button->load RECEIPT form
as soon as i click the save button, i want the records to be displayed in RECEIPT form.
all this operation happens in a single click.but i dont know how to retrieve it!please help.here is my codings :
[code]
With Adodc1
.Refresh
.Recordset.AddNew

.Recordset.Fields("Cust_Contact") = Txt_Contact.Text
.Recordset.Fields("Fac_Type") = Fac_type
.Recordset.Fields("Reserv_Date") = Now()
.Recordset.Fields("Booking_Time") = time
.Recordset.Fields("Cust_Name") = Txt_Name.Text

.Recordset.Update

MsgBox "Records have been successfully saved!", vbOKOnly

End With
End If
End If
Unload Me

Adodc1.RecordSource = (current record that has just been added)//i don't know how!
Adodc1.Recordset.Requery
Adodc1.Refresh

Receipt.Lbl_Amount.Caption = amount

Receipt.Lbl_ReservNo = Adodc1.Recordset.Fields("Reserv_No").Value
Receipt.Lbl_Name.Caption = Adodc1.Recordset.Fields("Cust_Name").Value
Receipt.Lbl_DateOfBooking.Caption = Adodc1.Recordset.Fields("Reserv_Date").Value
Receipt.Lbl_FacType.Caption = Adodc1.Recordset.Fields("Fac_Type").Value
Receipt.Lbl_DateIssued.Caption = Now()
Receipt.Lbl_CurrentUser.Caption = current_user

Receipt.Show

End Sub

nuBudDy
Light Poster
32 posts since Aug 2007
Reputation Points: 10
Solved Threads: 0
 

First of all, why do you have

unload me

in the middle of your sub? The program won't do the lines after that.
And now to your question, when you just added a record, then your recordset is pointing to that record so you can just do

Receipt.Lbl_Amount.Caption = amount

Receipt.Lbl_ReservNo = Adodc1.Recordset.Fields("Reserv_No").Value
Receipt.Lbl_Name.Caption = Adodc1.Recordset.Fields("Cust_Name").Value
Receipt.Lbl_DateOfBooking.Caption = Adodc1.Recordset.Fields("Reserv_Date").Value
Receipt.Lbl_FacType.Caption = Adodc1.Recordset.Fields("Fac_Type").Value
Receipt.Lbl_DateIssued.Caption = Now()
Receipt.Lbl_CurrentUser.Caption = current_user

Receipt.Show

and you don't need

Adodc1.RecordSource = (current record that has just been added)//i don't know how!
Adodc1.Recordset.Requery
Adodc1.Refresh

plusplus
Posting Whiz in Training
207 posts since Jul 2007
Reputation Points: 10
Solved Threads: 16
 

use the code in the attachment.
hope it will help you.

Attachments Code.zip (5.82KB)
choudhuryshouvi
Posting Pro
553 posts since May 2007
Reputation Points: 30
Solved Threads: 49
 

plusplus, thank you for your effort to help.does it really point to the current record because it didn't seem to work.maybe there is an error in other parts of the codes..

n choudhuryshouvi,thank you very much for your help,it worked well!

nuBudDy
Light Poster
32 posts since Aug 2007
Reputation Points: 10
Solved Threads: 0
 

Did you get your answer or do you still need help

plusplus
Posting Whiz in Training
207 posts since Jul 2007
Reputation Points: 10
Solved Threads: 16
 

another suggestion, inestead of getting a record from the database why dont you use the data from the textboxes or from the variables you have used to add? example:

with Receipt
          .Lbl_Amount.Caption = amounttxt.text
          .Lbl_ReservNo = ReservNo.text
          .Lbl_Name.Caption = CustName.Text
          .Lbl_DateOfBooking.Caption = Now
          .Lbl_FacType.Caption = FacType.Text
          .Lbl_DateIssued.Caption = Now
          .Lbl_CurrentUser.Caption = current_user
          .Show
     End with
jireh
Posting Whiz
316 posts since Jul 2007
Reputation Points: 11
Solved Threads: 49
 

plusplus,i already found the answer.thank you very much 4 ur concern.;)thanx again.

nuBudDy
Light Poster
32 posts since Aug 2007
Reputation Points: 10
Solved Threads: 0
 

If you got your answer then mark the thread solved

plusplus
Posting Whiz in Training
207 posts since Jul 2007
Reputation Points: 10
Solved Threads: 16
 

nuBudDy post your answer here please i want the solution for the same problem but i am not able to ge it thank you

bapu435
Newbie Poster
9 posts since Jul 2007
Reputation Points: 10
Solved Threads: 0
 

bapu435, the answer is in the zipfile provided by choudryshouvi

nuBudDy
Light Poster
32 posts since Aug 2007
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You