Results 1 to 9 of 9
  1. #1
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Gillingham, Kent, England
    Posts
    511
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Access to VB (VB 6)

    I've been working with Access for a while now and im just moving into VB. However, im still a bit used to the simple ways of Access.
    I havent yet installed the MSDN part of the installation therefore im currently without the help files! (Must free some harddrive space first).

    The simple question:
    I cant seem to find where to set the default value in text and combo boxes.

    For a bigger problem:

    Im trying to fix a database that was created by someone else. I have 2 combo boxes set up as an array (i.e. Both boxes named the same, 1 with an index of 0 and the other an index of 1).
    The current code passes a set of text and combo boxes to a function. The one in question is being passed to a Long variable using: CDbl(cmbCounty(1))
    The error 'Type mismatch' is returned.

    When looking into it I was attemping to see what was held in cmbCounty(1) (the combo box had been filled). I tried typing in the debug box print cmbCounty(1) but nothing was displayed. Would anybody have any ideas? If more info is required please feel free to request it.

    Thanks.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Access to VB (VB 6)

    I don't know if this is what you want. A VB6 text box and combo box have a Text property that determine the text that is displayed when the application starts. In run-time, the Text property holds the current value of the text box/combo box.

    CDbl converts a value to a double precision floating point number. To convert to a long integer, use CLng.

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Access to VB (VB 6)

    You might want to try using CLng(cmbCounty(1).Text). VB doesn't do as much coercian as Access does, so you usually are safest to specify the Text property rather than just the control itself when you want to know what it contains.
    Charlotte

  4. #4
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Gillingham, Kent, England
    Posts
    511
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Access to VB (VB 6)

    Thanks to you both for the tips.
    I have found the cause of the error but Im now wondering if there is a setting to fix it or if id need to write a code solution (which im okay to do, but am curious to see if there are settings to fix it):

    The array combo boxes cmbCounty(0) and cmbCounty(1) work fine if the user uses the mouse and selects an item from the dropdown. However, if a user manually types in a selection (that is in the list), the other combo box in the array does not get filled in (hence clng wouldnt work as the combo box was empty!).

    In Access, if a user makes an entry in a combo box the dropdown picks up what they are typing, is there a way of doing this in access? Also is there something i've missed that would make the 2nd combo box fill in even if the user types the entry in manually or would I need to write the code to update the contents of the 2nd box based on the entry?

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Access to VB (VB 6)

    Control events are different in VB from in Access, as you've discovered. If you have the combobox set as a Dropdown list in VB, it should do an automatic match, the same as an Access combobox but it doesn't have an AfterUpdate event, so you'll need to use either the Validate event or the Change event to make any changes to the other combo. The Validate event is close to the BeforeUpdate event of a control in Access. Just be sure to set the CausesValidation property of the control to true or it won't be triggered.
    Charlotte

  6. #6
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Gillingham, Kent, England
    Posts
    511
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Access to VB (VB 6)

    Ah, thats cleared a bit up, thanks. I guess its just a case of learning the differences between access and VB.

    However:
    Currently, the form load event populates the combo box (the content of the box, not the list). With the style set to dropdown combo formMain.cmbcounty(0) = rs.fields("County") works fine, however, with the style set to dropdown list it returns the error: text property is read only. Is there something im missing or can you not populate a dropdown box like this?
    Also are there any control options like "limit to list" or would I have to write them manually?

  7. #7
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Access to VB (VB 6)

    With the combo set that way, you get automatic matching and behavior much like an Access combobox, except it matches each character typed to the first matching item in the list. To set the combobox's value at run time, you need to set its ListIndex property, not its Text property.
    Charlotte

  8. #8
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Gillingham, Kent, England
    Posts
    511
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Access to VB (VB 6)

    Thanks for your help Charlotte.
    It must be said, taking over a program from a previous developer makes you appreciate the use of comments! A few more in the program i'm working on would have been handy.

  9. #9
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Access to VB (VB 6)

    Your comments made me <img src=/S/smile.gif border=0 alt=smile width=15 height=15> because I have spent the whole morning fixing a bug in a C program that I wrote 5 years ago. If it weren't for the comments I wouldn't have had a clue!

    StuartR

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •