CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2009
    Posts
    13

    Exclamation 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!

  2. #2
    Join Date
    Jan 2009
    Posts
    13

    Exclamation 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.

  3. #3
    Join Date
    Mar 2009
    Posts
    12

    Re: Help with a Sql Statement

    Have you opened the database with connection string?
    also you havent declared rst3.

    Declare them(Use Option Explicit).

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Help with a Sql Statement

    [ Merged ]

  5. #5
    Join Date
    Jan 2009
    Posts
    13

    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!

  6. #6
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    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
  •  





Click Here to Expand Forum to Full Width

Featured