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
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
Re: Help with a Sql Statement
Have you opened the database with connection string?
also you havent declared rst3.
Declare them(Use Option Explicit).
Re: Help with a Sql Statement
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
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?