-
Oct 13th, 2012, 03:20 AM
#1
Thread Starter
Member
ComboBox and MSHFlexGrid Problem
I'm using a MSHFlexGrid (fgdVehicle) to input data from a database ( via a recordset (rsVehicle) ).
You can either enter the data into the database in two ways :
1. From the database application
2. From a form.
The problem is present in the second method.
There are specific textboxes (txtID, txtModel, txtChassis and txtCompany) and a combobox (cboType) to enter the data into the certain fields, and when you click on the "Save" button, the data will get saved to the FlexGrid as a new record (also gets saved to the database at the same time).
My problem is, the text entered into the textboxes get saved into the record in the FlexGrid, but the option you select in the combobox of the form won't get shown (that column in the FlexGrid is empty). When I put a break-point and run the code, it shows that the combobox is empty, therefore, nothing is shown in the record for the combobox field.
Here is the code I'm using :
Code:
Dim rsVehicle As New ADODB.Recordset
Dim cn As New ADODB.Connection
Dim strSQL As String
cmdSaveNew.Enabled = True
cmdCancel.Visible = True
cn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & App.Path & "\Luckshan Tours & Travels.mdb;" & _
"Persist Security Info:False"
cn.Open
strSQL = "SELECT [Vehicle].* FROM [Vehicle]"
rsVehicle.Open strSQL, cn, adOpenStatic, adLockPessimistic
If rsVehicle.RecordCount <> 0 Then
rsVehicle.MoveLast
rsVehicle.AddNew
rsVehicle.Fields("Vehicle ID") = txtID
rsVehicle.Fields("Vehicle Model") = txtModel
rsVehicle.Fields("Chassis No") = txtChassis
rsVehicle.Fields("Vehicle Type") = cboType
rsVehicle.Fields("Companies Registerd To") = txtCompany
If txtID = "" Then
msg = MsgBox("Please enter Vehicle ID", vbExclamation, "Error")
Exit Sub
End If
ElseIf rsVehicle.RecordCount = 0 Then
rsVehicle.AddNew
rsVehicle.Fields("Vehicle ID") = txtID
rsVehicle.Fields("Vehicle Model") = txtModel
rsVehicle.Fields("Chassis No") = txtChassis
rsVehicle.Fields("Vehicle Type") = cboType
rsVehicle.Fields("Companies Registerd To") = txtCompany
If txtID = "" Then
msg = MsgBox("Please enter Vehicle ID", vbExclamation, "Error")
Exit Sub
End If
End If
rsVehicle.Update
cmdBack.Enabled = True
cmdDelete.Enabled = True
cmdLogOut.Enabled = True
cmdUpdate.Enabled = True
cmdRefresh.Enabled = True
cmdSearch.Enabled = True
cmdAdd.Enabled = True
Me.cmdSaveNew.Enabled = False
msg = MsgBox("Record Saved.", vbInformation, "Notification")
cmdCancel.Visible = False
Set fgdVehicle.DataSource = rsVehicle
rsVehicle.Update
Last edited by Skate Bart; Oct 14th, 2012 at 10:06 AM.
-
Oct 13th, 2012, 06:51 AM
#2
Re: ComboBox and MSHFlexGrid Problem
What is this line?
rsVehicle.Fields("Companies Registerd To") = txtCompany dset (rsVehicle).
? comes up as an incorrect command ?
-
Oct 13th, 2012, 06:58 AM
#3
Re: ComboBox and MSHFlexGrid Problem
The 'value' of cboType is many (the whole list within the combo box). I don't think you can send that directly to a field....what you want to send to the field (grid and db) is cboType.text.
-
Oct 13th, 2012, 10:31 AM
#4
Re: ComboBox and MSHFlexGrid Problem
Yes you shoudl be referencing either the text property or the List(index) property of the combo. You shoudl also be using the text property of the text boxes as well. VB6 and before will let you get away with omitting the .text property on textboxes and takes a guess that is what you want but after VB6 it will not work that way and is a bad habit to get into.
It is also not a good idea to use spaces in your database field or table names.
-
Oct 14th, 2012, 10:05 AM
#5
Thread Starter
Member
Re: ComboBox and MSHFlexGrid Problem
Originally Posted by SamOscarBrown
What is this line?
rsVehicle.Fields("Companies Registerd To") = txtCompany dset (rsVehicle).
? comes up as an incorrect command ?
Please ignore that. it was a typing error. Here is the correct statement :
rsVehicle.Fields("Companies Registerd To") = txtCompany
thnx for pointing it out. fixed it in the original post too.
-
Oct 14th, 2012, 10:06 AM
#6
Thread Starter
Member
Re: ComboBox and MSHFlexGrid Problem
Originally Posted by SamOscarBrown
The 'value' of cboType is many (the whole list within the combo box). I don't think you can send that directly to a field....what you want to send to the field (grid and db) is cboType.text.
tired it. still doesn't work! any ideas?
-
Oct 14th, 2012, 10:07 AM
#7
Thread Starter
Member
Re: ComboBox and MSHFlexGrid Problem
Originally Posted by DataMiser
Yes you shoudl be referencing either the text property or the List(index) property of the combo. You shoudl also be using the text property of the text boxes as well. VB6 and before will let you get away with omitting the .text property on textboxes and takes a guess that is what you want but after VB6 it will not work that way and is a bad habit to get into.
It is also not a good idea to use spaces in your database field or table names.
i tried the text property, list and index. none of them work!
-
Oct 14th, 2012, 11:05 AM
#8
Re: ComboBox and MSHFlexGrid Problem
You should show us how you tried it and tell us what result you did get. Telling us that you tried it and it didn't work doesn't really help much. You could have did it wrong or there may be some other problem.
Tags for this Thread
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
|