Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21839

ComboBox and MSHFlexGrid Problem

$
0
0
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 dset (rsVehicle).
    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


Viewing all articles
Browse latest Browse all 21839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>