Results 1 to 10 of 10
  1. #1
    Join Date
    Oct 2003
    Location
    the Netherlands
    Posts
    15

    Question Unanswered: How do I Select data & put it in a textbox at Form_Load?

    How do I Select data & put it in a textbox at Form_Load?
    This doesn't work. Could someone help me, please?
    I get Runtime error #91: Object Variable not Set
    ----------------------------

    ' *** Form_frmNewPShape ***
    Private Sub Form_Load()

    Dim db As DAO.DataBase
    Dim maxSIDRS As New ADODB.Recordset
    Dim strShapeID As String

    strShapeID = "SELECT Max(ShapeID) FROM Shapes"
    Set maxSIDRS = db.OpenRecordset(strShapeID, dbOpenDynaset)

    txtShapeID.Text = maxSIDRS("ShapeID")

    End Sub
    Last edited by Tjung; 10-23-03 at 11:28.

  2. #2
    Join Date
    Oct 2003
    Location
    US
    Posts
    343

    Re: How do I Select data & put it in a textbox at Form_Load?

    You are making a slight mistake in your code.Check the line where you typed:

    txtShapeID.Text = maxSIDRS("ShapeID")

    This is wrong. Correct syntax is

    txtShapeID = maxSIDRS("ShapeID")
    or
    txtShapeID.Value = maxSIDRS("ShapeID")

    remember Value is the default property so you can get away with either of the above two formats.



    Originally posted by Tjung
    How do I Select data & put it in a textbox at Form_Load?
    This doesn't work. Could someone help me, please?
    I get Runtime error #91: Object Variable not Set
    ----------------------------

    ' *** Form_frmNewPShape ***
    Private Sub Form_Load()

    Dim db As DAO.DataBase
    Dim maxSIDRS As New ADODB.Recordset
    Dim strShapeID As String

    strShapeID = "SELECT Max(ShapeID) FROM Shapes"
    Set maxSIDRS = db.OpenRecordset(strShapeID, dbOpenDynaset)

    txtShapeID.Text = maxSIDRS("ShapeID")

    End Sub

  3. #3
    Join Date
    Oct 2003
    Location
    Roanoke, Va
    Posts
    445

    Smile Re: How do I Select data & put it in a textbox at Form_Load?

    Originally posted by Tjung
    How do I Select data & put it in a textbox at Form_Load?
    This doesn't work. Could someone help me, please?
    I get Runtime error #91: Object Variable not Set
    ----------------------------

    ' *** Form_frmNewPShape ***
    Private Sub Form_Load()

    Dim db As DAO.DataBase
    Dim maxSIDRS As New ADODB.Recordset
    Dim strShapeID As String

    strShapeID = "SELECT Max(ShapeID) FROM Shapes"
    Set maxSIDRS = db.OpenRecordset(strShapeID, dbOpenDynaset)

    txtShapeID.Text = maxSIDRS("ShapeID")

    End Sub
    You need to set db = CurrentDb

    Gregg

  4. #4
    Join Date
    Oct 2003
    Location
    the Netherlands
    Posts
    15
    Now I've got runtime-error 13:Type Mismatch

    Set maxSIDRS = db.OpenRecordset(strShapeID, dbOpenDynaset) is still marked in yellow

  5. #5
    Join Date
    Oct 2003
    Location
    Roanoke, Va
    Posts
    445

    Smile

    Originally posted by Tjung
    Now I've got runtime-error 13:Type Mismatch

    Set maxSIDRS = db.OpenRecordset(strShapeID, dbOpenDynaset) is still marked in yellow
    You are using DAO for your database reference and then ADO for your recordset reference. Just try using DAO for the recordset reference since that's the way you have constructed your openrecordset method. Then set the db = CurrentDb. Also, try in your string statement, "Select Max(ShapeID) As ShapeMax from Shapes".

    Dim db As DAO.DataBase
    Dim maxSIDRS As DAO.Recordset
    Dim strShapeID As String
    Set db = CurrentDb
    strShapeID = "SELECT Max(ShapeID) As ShapeMax FROM Shapes"
    Set maxSIDRS = db.OpenRecordset(strShapeID, dbOpenDynaset)

    txtShapeID.Text = maxSIDRS("ShapeMax")

    It's early AM, so I hope I'm thinking clear enough. If not, I'm sure someone will tell me.

    Good luck.

    Gregg

  6. #6
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    basicmek is using .Text ...and that wont work til you set focus to the text box. but you are probably complicating your life.

    in design view, your textbox, data, defaultvalue. how about:
    dmax("shapeid", "shapes")

    i know there are objections to domain aggregate functions (some folk say they are slow), but how many times a day can you reinvent a faster wheel? .

    ..and is dmax really that much slower than all the messing with constructing the recordset?

    izy
    currently using SS 2008R2

  7. #7
    Join Date
    Oct 2003
    Location
    Roanoke, Va
    Posts
    445

    Smile

    Originally posted by izyrider
    basicmek is using .Text ...and that wont work til you set focus to the text box. but you are probably complicating your life.

    in design view, your textbox, data, defaultvalue. how about:
    dmax("shapeid", "shapes")

    i know there are objections to domain aggregate functions (some folk say they are slow), but how many times a day can you reinvent a faster wheel? .

    ..and is dmax really that much slower than all the messing with constructing the recordset?

    izy
    Izy:

    I was just copying and pasting his code and trying to subsitute into the areas that I was talking about. I was leaving the .text vs .value stuff to others since it had already been mentioned.

    Keep an eye on me though, especially when I indicate that it is early AM.

    Gregg
    Last edited by basicmek; 10-24-03 at 23:18.

  8. #8
    Join Date
    Oct 2003
    Location
    the Netherlands
    Posts
    15
    Originally posted by izyrider
    basicmek is using .Text ...and that wont work til you set focus to the text box. but you are probably complicating your life.

    in design view, your textbox, data, defaultvalue. how about:
    dmax("shapeid", "shapes")

    i know there are objections to domain aggregate functions (some folk say they are slow), but how many times a day can you reinvent a faster wheel? .

    ..and is dmax really that much slower than all the messing with constructing the recordset?

    izy
    I tried DMax("ShapeID", "Shapes") already, but it doesn't work.
    "The expression you entered contains invalid syntax"

  9. #9
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    if you have a table called shapes containing a field called shapeid, dmax("shapeid", "shapes") should work fine.

    izy
    currently using SS 2008R2

  10. #10
    Join Date
    Oct 2003
    Location
    the Netherlands
    Posts
    15
    Nvm I got it already with DAO. Anyway thnx!

    Tjung

Posting Permissions

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