ComboBox and MSHFlexGrid Problem-VBForums
Results 1 to 8 of 8

Thread: ComboBox and MSHFlexGrid Problem

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2012
    Posts
    41

    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.

  2. #2
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    6,265

    Re: ComboBox and MSHFlexGrid Problem

    What is this line?

    rsVehicle.Fields("Companies Registerd To") = txtCompany dset (rsVehicle).

    ? comes up as an incorrect command ?

  3. #3
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    6,265

    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.

  4. #4
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    12,138

    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.

  5. #5

    Thread Starter
    Member
    Join Date
    Jun 2012
    Posts
    41

    Re: ComboBox and MSHFlexGrid Problem

    Quote Originally Posted by SamOscarBrown View Post
    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.

  6. #6

    Thread Starter
    Member
    Join Date
    Jun 2012
    Posts
    41

    Re: ComboBox and MSHFlexGrid Problem

    Quote Originally Posted by SamOscarBrown View Post
    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?

  7. #7

    Thread Starter
    Member
    Join Date
    Jun 2012
    Posts
    41

    Re: ComboBox and MSHFlexGrid Problem

    Quote Originally Posted by DataMiser View Post
    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!

  8. #8
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    12,138

    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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.