944,117 Members | Top Members by Rank

Ad:
Sep 20th, 2007
0

retrieving current record in database

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
nuBudDy is offline Offline
32 posts
since Aug 2007
Sep 21st, 2007
0

Re: retrieving current record in database

First of all, why do you have
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. 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

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Receipt.Lbl_Amount.Caption = amount
  2.  
  3. Receipt.Lbl_ReservNo = Adodc1.Recordset.Fields("Reserv_No").Value
  4. Receipt.Lbl_Name.Caption = Adodc1.Recordset.Fields("Cust_Name").Value
  5. Receipt.Lbl_DateOfBooking.Caption = Adodc1.Recordset.Fields("Reserv_Date").Value
  6. Receipt.Lbl_FacType.Caption = Adodc1.Recordset.Fields("Fac_Type").Value
  7. Receipt.Lbl_DateIssued.Caption = Now()
  8. Receipt.Lbl_CurrentUser.Caption = current_user
  9.  
  10. 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
Last edited by plusplus; Sep 21st, 2007 at 1:45 am.
Reputation Points: 10
Solved Threads: 16
Posting Whiz in Training
plusplus is offline Offline
207 posts
since Jul 2007
Sep 21st, 2007
0

Re: retrieving current record in database

use the code in the attachment.
hope it will help you.
Attached Files
File Type: zip Code.zip (5.8 KB, 144 views)
Reputation Points: 30
Solved Threads: 49
Posting Pro
choudhuryshouvi is offline Offline
553 posts
since May 2007
Sep 21st, 2007
0

Re: retrieving current record in database

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!
Reputation Points: 10
Solved Threads: 0
Light Poster
nuBudDy is offline Offline
32 posts
since Aug 2007
Sep 21st, 2007
0

Re: retrieving current record in database

Did you get your answer or do you still need help
Reputation Points: 10
Solved Threads: 16
Posting Whiz in Training
plusplus is offline Offline
207 posts
since Jul 2007
Sep 21st, 2007
0

Re: retrieving current record in database

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:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. with Receipt
  2. .Lbl_Amount.Caption = amounttxt.text
  3. .Lbl_ReservNo = ReservNo.text
  4. .Lbl_Name.Caption = CustName.Text
  5. .Lbl_DateOfBooking.Caption = Now
  6. .Lbl_FacType.Caption = FacType.Text
  7. .Lbl_DateIssued.Caption = Now
  8. .Lbl_CurrentUser.Caption = current_user
  9. .Show
  10. End with
Last edited by jireh; Sep 21st, 2007 at 4:49 am.
Reputation Points: 11
Solved Threads: 49
Posting Whiz
jireh is offline Offline
316 posts
since Jul 2007
Sep 23rd, 2007
0

Re: retrieving current record in database

plusplus,i already found the answer.thank you very much 4 ur concern.thanx again.
Reputation Points: 10
Solved Threads: 0
Light Poster
nuBudDy is offline Offline
32 posts
since Aug 2007
Sep 24th, 2007
0

Re: retrieving current record in database

If you got your answer then mark the thread solved
Reputation Points: 10
Solved Threads: 16
Posting Whiz in Training
plusplus is offline Offline
207 posts
since Jul 2007
Nov 30th, 2007
0

Re: retrieving current record in database

nuBudDy post your answer here please i want the solution for the same problem but i am not able to ge it thank you
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bapu435 is offline Offline
9 posts
since Jul 2007
Dec 22nd, 2007
0

Re: retrieving current record in database

bapu435, the answer is in the zipfile provided by choudryshouvi
Reputation Points: 10
Solved Threads: 0
Light Poster
nuBudDy is offline Offline
32 posts
since Aug 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: What is Form in VB6
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: resizing toolbar





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC