|
|
|||||||||
|
|||||||||
|
|||||||||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
sql woes......combo box doom...help!!pls
Right this is a big ask but im desprate....
The general jist of my project is that it is a computerised car hire program for my A-Level project. I have seven forms all of which are working fine except this one. It is the "HireACar" form... Im trying to populate two combo boxes with data from an access database and its driving me nuts. I have set up a data enviroment call deCar and have four tables, Car_Details, Staff_Details, Customer_Details and Prices. I have been able to view, ammend and create new records in these tables, via the the data connection in other forms and this works ok e.g. decar.rsCar_Details.Update etc. In the form im having trouble with i have two combo boxes, 1) (CboCat) I wish to call the field catergory from the "prices" table and for all the catergories to appear in this combo box list. (there are 5 categories A, B, C, D and E, which each have an individual price of hire per week and per day, e.g a car which is catergory A costs £39.99 per day and £150 per week) this Prices table is linked to the "model" field in the "Car_Details" table via access relationship. Im wanting to set it up so that these 5 catergories appear in the combo box (I cant even do this(SQL i THINK) and when the user picks a catergory for 3 things to happen: 1)all car models in the chosen catergory to apper in a second combo box (car model is a field in the car_details table, which is linked to the catergory field in the prices table) 2)The price per day for this catergory (catergory is the primary key in the "prices" table and the foriegn key in the "car_details" table) to apper in a lablel on this form (lblPricePerDay) 3)the price per week to apper in a label on this form (lblPricePerWeek) I have attempted some code but it is really confusing and frustrating me: This is a mess I know..and is no were near doing what i wish it too HELP!!: Dim myConnection As ADODB.Connection Dim myRecordSet As ADODB.Recordset Dim mySQL As String Set myConnection = New ADODB.Connection mySQL = "SELECT [Car Details].[Model] FROM Prices INNER JOIN [Car Details] ON [Prices].[Catergory]=[Car Details].[Category] WHERE ((([Car Details].[Category])=[Please choose a catergory?]));" //this is a mess and does nothing!!!!HELP I want this to get all model for the chosen catergory AND the price per day/week for the chosen catergory, but the models are stored in a differnt table to the prices and categories, they are linked through the catergory field, which is the primary key in the prices table and the foriegn key in the car_details table// myConnection.ConnectionString = _ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Copy of CPT6(rough attempt).mdb" myConnection.Open Set myRecordSet = myConnection.Execute("mySQL") myRecordSet.Close myConnection.Close This is my only ideas on how to popualte the combo box...bolloxs I know just so you dont think I havent tried thats all!! Private Sub Form_Load() Dim dbs As Database '??? I know i cant decale something as a database but am unsure what to do!!! Dim rst As ADOBB.Recordset Dim x As Integer HireACar.Width = 10635 HireACar.Height = 7455 HireACar.Left = 2625 HireACar.Top = 1530 lblDate.Caption = Date dbs = OpenDatabase("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Copy of CPT6(rough attempt).mdb") rst = dbs.OpenRecordset(CarDetails, dbOpenDynaset) With rst If rst.RecordCount = 0 Then Exit Sub Else For x = 0 To rst.RecordCount cboCat.AddItem rst.MoveNext Next End If End With rst = Nothing dbs = Nothing End Sub //If this did work id still need to get the three bits o data for each catergory AGHHHHHHHH!!!! This doesnt seem to work, as i dont know how to declaere something as a database....HELP also if i get this working i dont know how to "get the models (car_details table)for the chosen catergory, or the price per week/day (prices table) I would be eternally gratefull for any ideas!!!The SQL is my biggest problem as I cant write it manually (this 'complicated' anyhows) I just ripp it of access and it confuses me!!! |
|
#2
|
|||
|
|||
|
For starter you are mixing up ADO and DAO referencing.
dbs = OpenDatabase("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Copy of CPT6(rough attempt).mdb") rst = dbs.OpenRecordset(CarDetails, dbOpenDynaset) dbs ... is DAO Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Copy of CPT6(rough attempt).mdb... is ADO Where your DB is in access, you access to help you write you SQL outside of that I don't know how much more I am willing to help you (this sound like a school project). S- |
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > sql woes......combo box doom...help!!pls |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|