Discussion Locked

Somebody pls help!!!!!! MS Access/VB6.0 query problem

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Can someone help me pls. I'm developing an application for my small travels and tours agency that will handle the personal information and reservation requests of customers. I want a situation where when I click the view reservations button from within the customer page, the "Reservation form" will load and displayed only the results matching the customer ID as shown on the "View Customer" form customer ID textbox.

Below is the form load event procedure that I have which is not working:

Private Sub Form_Load()
Dim strSQL As String
strSQL = "SELECT * FROM reservation WHERE cusIdNum = CusIDval"
res_Edith_btn.Enabled = False

End Sub

"reservation" is the name of the table to hold reservation information of various customers.

"cusIdNum" is the name of the customer identifier ID field on the reservation table as picked from the customer ID textbox when adding a reservation.

"CusIDval' is public declaration value of the customer ID textbox on the customer view page.

7 replies

by rick

You need to fix your strSQL - it needs to be
strSQL = "SELECT * FROM reservation WHERE cusIdNum =" & txtCusIDval.Text
If you are having the user enter a value from a textbox. It would be different if using a listbox or combo.

Good luck

by dr dij

I think you need single quotes around the value
.. where custidnum = '" & [textbox].text & "'"
I use them on later versions.

plus just assigning string to a sql command doesn't get the data from the database. I presume you connect to the database and send the strSQL to it somewhere?

by deyshele

Pls people and fellow coders. I have tried all the suggestion that has been raised but none has worked so far. Should I upload the entire package for assistance? Can someone pls help me take a look at it? If any is willing to help, send me your email addy so I can send it across.

by support

Private Sub Form_Load()
Dim strSQL As String
strSQL = "SELECT * FROM reservation WHERE cusIdNum = '" & CusIDval & "'"
'yourconnection.execute strSQL
res_Edith_btn.Enabled = False

End Sub

by gumdropps

Your code goes nowhere. You're filling a string with code to open a recordset that isn't defined. You have to define the recordset you are opening, add a long variable to hold the clientID and place that at the end of the string to open the recordset to that client. Without going thru all of that process, why not put a bound subform of a parent to child reference with the clientID and forget all of the code? The only thing you need in the button is a requery when the client ID changes.

by irinar

Hi! Try this code:

Private Sub Form_Load()
Dim strSQL As String

' CusIDval must be Long data type
strSQL = "SELECT * FROM reservation WHERE cusIdNum = " & CusIDval

' Assign your strSQL to the Form RecordSource
Me.RecordSource = strSQL

res_Edith_btn.Enabled = False

End Sub

This discussion is closed to new replies.