|
-
August 11th, 2009, 12:36 AM
#1
Help with a Sql Statement
Hi im trying to use a sql statement to save a record in a database the procedure is a follows
Form (name : frmBooking_Counter)
txtboxes(SS) (names : txtPassengerName;txtTicketNumber;txtArrival;txtDepartingAirport)
command button (name: cmdSave)
I have used this code but it doesnt work may someone help
Line2 is reporting a type mismatch
Code:
Private Sub cmdSave_Click()
Set rst3 = datReservationRecs.OpenRecordset("select * from Tickets where SS# ='" & [Form3s]!3)[Booking_Counter]![SS] & '";")
rst3.Save
rst3![PassengerName] = [Forms]![frmBooking_Counter]![txtPassengerName]
rst3![TicketNumber] = [Forms]![frmBooking_Counter]![txtTicketNumbers]
rst3![Arrival] = [Forms]![frmBooking_Counter]![txtArrival]
rst3![DepartingAirport] = [Forms]![frmBooking_Counter]![txtDepartingAirport]
rst3![Fare] = [Forms]![frmBoooking_Counter]![txtFare]
rst3![Class] = [Forms]![frmBooking_Counter]![txtClass]
rst3.Update
End Sub
have used this code but it doesnt work may someone help
Last edited by HanneSThEGreaT; August 11th, 2009 at 04:26 AM.
Reason: Code Tags!
-
August 11th, 2009, 12:40 AM
#2
Help with a Sql Statement
Hi im trying to use a sql statement to save a record in a database the procedure is a follows
Form (name : frmBooking_Counter)
txtboxes(SS) (names : txtPassengerName;txtTicketNumber;txtArrival;txtDepartingAirport)
command button (name: cmdSave)
I have used this code but it doesnt work may someone help
Line2 is reporting a type mismatch
1)Private Sub cmdSave_Click()
2Set rst3 = datReservationRecs.OpenRecordset("select * from Tickets where SS# ='" & , [Form3s]![Booking_Counter]![SS] & '";")
3)rst3.Save
4)rst3![PassengerName] = [Forms]![frmBooking_Counter]![txtPassengerName]
5)rst3![TicketNumber] = [Forms]![frmBooking_Counter]![txtTicketNumbers]
6)rst3![Arrival] = [Forms]![frmBooking_Counter]![txtArrival]
7)rst3![DepartingAirport] = [Forms]![frmBooking_Counter]![txtDepartingAirport]
8)rst3![Fare] = [Forms]![frmBoooking_Counter]![txtFare]
9)rst3![Class] = [Forms]![frmBooking_Counter]![txtClass]
10)rst3.Update
11)End Sub
Last edited by SNAREZ; August 11th, 2009 at 12:58 AM.
-
August 11th, 2009, 01:15 AM
#3
Re: Help with a Sql Statement
Have you opened the database with connection string?
also you havent declared rst3.
Declare them(Use Option Explicit).
-
August 11th, 2009, 04:23 AM
#4
Re: Help with a Sql Statement
-
August 11th, 2009, 04:49 AM
#5
Re: Help with a Sql Statement
I have tried declaring rst3 but still
Set rst3 =datReservationRecs.OpenRecordset("select*from Tickets where SS# = '"&[Forms]![Booking_Counter]![SS]&'";")
Code:
Option Explicit
Dim rst3 As Recordset
Private Sub cmdSave_Click()
Dim rst3 As Recordset
Set rst3 = datReservationRecs.OpenRecordset("select * from Tickets where SS# ='" & [Forms]![Booking_Counter]![SS] & '";")
rst3.Save
rst3![PassengerName] = [Forms]![frmBooking_Counter]![txtPassengerName]
rst3![TicketNumber] = [Forms]![frmBooking_Counter]![txtTicketNumbers]
rst3![Arrival] = [Forms]![frmBooking_Counter]![txtArrival]
rst3![DepartingAirport] = [Forms]![frmBooking_Counter]![txtDepartingAirport]
rst3![Fare] = [Forms]![frmBoooking_Counter]![txtFare]
rst3![Class] = [Forms]![frmBooking_Counter]![txtClass]
rst3.Update
End Sub
Last edited by HanneSThEGreaT; August 11th, 2009 at 06:05 AM.
Reason: Code Tags!
-
August 12th, 2009, 07:53 AM
#6
Re: Help with a Sql Statement
In the code above you are using a DAO recordset. DAO requires the use of the edit method.
On the line where you have rst3.save you need to have rst3.edit instead if you are changing the record or rst3.addnew if you are appending a new record.
In the case of edit you do know that the code will simply change the first record returned by your select, if any right?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|