Results 1 to 11 of 11
  1. #1
    Join Date
    Feb 2004
    Posts
    59

    Unanswered: Newbie Trouble with VB6

    Hello All-

    I'm taking an Access 2000 database built program and completely re-writing it in Visual Basic for distribution. I'm finding that a lot of my code is different, even though it was originally written in VBA.

    Anyway,

    I am trying to take information from a current recordset and place it into textboxes on a form, but my old code doesn't work anymore.

    My old code was:

    txtFirstName.Value = rs!FirstName
    txtLastName.Value = rs!LastName

    I've also tried:
    me.txtFirstName = rs!FirstName
    me.txtLastName = rs!LastName

    Neither work. OF course, this is after opening and finding the recordset. I do see that I can make a workaround of using label's instead of textboxes, in the form of:
    lblFirstName.Caption = rs!FirstName

    but I need it to be a textbox, so that it can be changed, and update the recordset later. I do NOT wish to bind the textbox. It needs to be unbound.

    I know this should be simple, but its got me stumped and my whole program uses this very often!

    Any ideas anyone?
    Thanks so much in advance!
    -Matt H-
    www.comperfection.com

  2. #2
    Join Date
    Jul 2004
    Posts
    69
    hi there! have you tried using the Text property of the textbox? instead of using the Value property use Text property,

    txtFirstName.Text = rs!FirstName

    or else leave it like this:

    txtFirstName = rs!FirstName

    hope this one helps...

  3. #3
    Join Date
    Feb 2004
    Posts
    59

    unfortunate

    unfortunately, when i try:

    txtFirstname.Text = rs!FirstName
    or
    txtFirstName = rs!FirstName

    I get "Invalid Use of Property".

    maybe I need to try and check the properties of the textbox again on the main form? Also, would declaring the form in the full path be better? I mean, right now, I'm calling this from the "On_Load" for the main form, but maybe it's losing the mainform title. So, I'm thinking maybe calling it as such might help?

    [frmMain].[txtFirstName] ([.Text] if necessary) = rs!FirstName

    Any thoughts from anyone whos done this before? I've been stumped for hours trying all sorts of variations that i KNOW worked with VBA!
    -Matt H-
    www.comperfection.com

  4. #4
    Join Date
    Nov 2004
    Posts
    3

    Unbound

    Try this in VB6:
    set cn=new connection
    set rs=new recordset
    strprovider ="microsoft.jet.oledb4.0;data source=c:\........."
    'The ..... is where your database is located at.

    cn.open strprovider
    re.open "Select * from _______",cn


    set textbox1.datasource = rs
    textbox1.datafield = rs.fields(1)name

  5. #5
    Join Date
    Nov 2004
    Posts
    3

    Disregard last post

    Disregard the last post - won't work

  6. #6
    Join Date
    Jul 2004
    Posts
    69
    Quote Originally Posted by mateo107
    unfortunately, when i try:

    txtFirstname.Text = rs!FirstName
    or
    txtFirstName = rs!FirstName

    I get "Invalid Use of Property".
    are you sure you're using the Textbox control? it's very unusual to have that kind of error. dunno what's going on there...

  7. #7
    Join Date
    May 2004
    Posts
    97
    Try assigning the database value to a variable first, then the variable to the textbox.

    i.e.

    varFirstName = rs!FirstName
    txtFirstName.text = varFirstName

  8. #8
    Join Date
    Feb 2004
    Posts
    59

    Cool textbox trouble continued...

    OK- well I've tried the aforementioned - setting the rs!FirstName to a string first, and then using the txtFirstName.Text = the string, same error.

    When I autolist the textbox 'Properties/Methods', it only comes up with: Count, Item, LBound, UBound...

    could this be a problem with a reference? i think I may have deleted one by mistake.

    Also, I'm positive this is a textbox. I've removed it and re-added it, making sure to select textbox - and using the default values - except i changed the name to txtFirstName - and i get the same error

    anybody else have any ideas? This is driving me crazy! Everything tells me that the .text property should work...

    UPDATED:
    So - I created a new 'dummy' form and used the same coding:
    txtFirstName.Text = rs!FirstName

    and it worked, so I copied all the references down, moved to mine, and they were slightly different, but when I changed mine to match, I get the same error.

    Its referencing:
    VB for Applications / VB runtime objects and procedures / VB objects and procedures / OLE Automation / MS ActiveX Data Objects 2.0 / and MS DAO 3.6 Object Library...

    what the heck could be the problem? I'm losing my hair over here! :-/

    Thanks again for all the suggestions this far everyone! I think, we're getting somewhere - i hope
    Last edited by mateo107; 11-03-04 at 19:56. Reason: UPDATE
    -Matt H-
    www.comperfection.com

  9. #9
    Join Date
    Nov 2004
    Posts
    3

    Lightbulb Put code in message:

    Would you put you code in a reply so it can be looked at.

  10. #10
    Join Date
    Jul 2004
    Posts
    69
    it looks like you got a control array. determine the index number of the textbox control by looking at the Index property of the control in the property box or you can determine the index number by looking at the control name. it should look like txtFirstName(x) where x is the index number. for example:

    txtFirstname(0).Text = rs!Firstname

    take not that when you're using a control array, only the 'Properties/Methods that comes up with are the one you mentioned in your post. Count, Item, LBound, UBound...

  11. #11
    Join Date
    Feb 2004
    Posts
    59

    got it!

    I think you may be correct. I think i mistakenly entered a control array on that page. By re-creating the page in its entirety, I was able to solve the problem (but I was hoping not to).

    Now it works fine.

    Thank you all though!
    -Matt H-
    www.comperfection.com

Posting Permissions

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