Results 1 to 13 of 13
  1. #1
    Join Date
    Mar 2005
    Posts
    27

    Unanswered: run-time error '91'

    Hi, I'm a newbie to VB and I'm just trying to get to grips with SQL as well as VB before I try to implement them

    My code is as follows:

    Private Sub Command1_Click()

    Dim Conn As New ADODB.Connection, SQL As String, Cmd As Command, RS As Recordset


    SQL = "SELECT * FROM INTMATCHDET"

    Conn.ConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0;" & _
    "Persist Security Info=False;" & _
    "Data Source =C:\Documents and Settings\Chander\My Documents\Uni Files\Temp DBs\dbconv6.mdb"

    Conn.Open



    RS.Open SQL, Conn

    Set Conn = Nothing
    Set RS = Nothing

    End Sub



    I was hoping this would display a few records I have in a small table. Do I need something else to actially display my results in?

    Appreciate any help, thanks in advance

  2. #2
    Join Date
    Dec 2004
    Location
    Laguna, Philippines
    Posts
    147
    yup! you need to indicate where to display your records.. i.e. datagrid, textbox..
    Give me a place to code and i shall move the earth!

  3. #3
    Join Date
    Dec 2004
    Location
    Laguna, Philippines
    Posts
    147
    also...

    Dim Conn As New ADODB.Connection, SQL As String, Cmd As Command, RS As New ADODB.Recordset
    Give me a place to code and i shall move the earth!

  4. #4
    Join Date
    Mar 2005
    Posts
    27

    Smile

    Hey hey, I've sorta changed my code but tryin to do the same thing...

    Problem is that I don't get any errors now, but my DBCombox is just empty!!

    Assuming my SQL statement is correct (since it's so simple...) why might this happen?

    ----------------------------------------------------------------------

    Private Sub DBCombo1_Click(Area As Integer)
    Dim Conn As New ADODB.Connection, RS As New ADODB.Recordset
    Dim CMD As New ADODB.Command

    'Connect to Access database on my hard-drive
    Conn.ConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0;" & _
    "Persist Security Info=False;" & _
    "Data Source =C:\Documents and Settings\Chander\My Documents\Uni Files\Temp DBs\dbconv1.mdb"
    Conn.Open

    CMD.ActiveConnection = Conn

    'SQL SELECT Query
    CMD.CommandText = "SELECT Surname FROM INT_PLAYER WHERE Category = 'Bowler'"
    CMD.CommandType = adCmdText

    Set RS = CMD.Execute

    End Sub

    ----------------------------------------------------------------------


    Also, any way I can find out how to use this gridbox idea? Sounds intriguing

    Thanks a bunch

  5. #5
    Join Date
    Dec 2004
    Location
    Laguna, Philippines
    Posts
    147
    'link your control to recordset...

    Set DBCombo1.DataSource = RS
    DBCombo1.DataField = "Surname"
    Give me a place to code and i shall move the earth!

  6. #6
    Join Date
    Mar 2005
    Posts
    27
    " "
    Set DBCombo1.DataSource = RS
    DBCombo1.DataField = "Surname"

    Hi, I tried inserting that piece of code into mine before the execute command and just after but I still have an empty DBCombox.

    Do I have to replace any code with the above lines, or is there somewhere specific I need to insert it?

    Thanks again for any help

  7. #7
    Join Date
    Dec 2004
    Location
    Laguna, Philippines
    Posts
    147
    nop! your codes seems fine to me but you must itsert the new code AFTER the execute command.

    Set RS = CMD.Execute
    Set DBCombo1.DataSource = RS
    DBCombo1.DataField = "Surname"
    Give me a place to code and i shall move the earth!

  8. #8
    Join Date
    Mar 2005
    Posts
    27
    Hello again, really sorry to keep buggin you but there's a little something still missing.

    As it stands, the drop-down menu now only returns one result. The SQL statement must be working (I hope) because the surname returned is one where the category is 'bowler'.

    Also, this result only appears is the Style is set to '0 - dbcDropDownCombo'

    Is there some reason why this might be happening????

  9. #9
    Join Date
    Dec 2004
    Location
    Laguna, Philippines
    Posts
    147
    i tried the code and it shows also the same result. i also wonder why return only one record, but i tried an alternative that will show all recods but it will change some of your codes.

    heres my code...

    Dim Conn As New ADODB.Connection, RS As New ADODB.Recordset

    'Connect to Access database on my hard-drive
    Conn.ConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0;" & _
    "Persist Security Info=False;" & _
    "Data Source =C:\Documents and Settings\Chander\My Documents\Uni Files\Temp DBs\dbconv1.mdb"
    Conn.Open

    'SQL SELECT Query
    Rs.CursorLocation = adUseClient
    Rs.Open "SELECT Surname FROM INT_PLAYER WHERE Category = 'Bowler'", Conn, AdOpenDynamic

    Set DataCombo1.RowSource = RS
    DBCombo1.Text = ""
    DBCombo1.ListField = "Surname"
    DBCombo1.BoundColumn = ""

    Also, why dont put this codes somewhere else rather than in dbcombo1_click event.
    Just some advise....
    Give me a place to code and i shall move the earth!

  10. #10
    Join Date
    Mar 2005
    Posts
    27
    Hello again,

    (Thanks for putting so much effort into helping me, it is much appreciated).

    I tried the code you gave me and for some reason I got a runtime error 424.
    Not sure why this is.


    I've highlighted the line that VB tells me is responsible for the error:






    Dim Conn As New ADODB.Connection, RS As New ADODB.Recordset

    'Connect to Access database on my hard-drive
    Conn.ConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0;" & _
    "Persist Security Info=False;" & _
    "Data Source =C:\Documents and Settings\Chander\My Documents\Uni Files\Temp DBs\dbconv1.mdb"
    Conn.Open

    'SQL SELECT Query
    RS.CursorLocation = adUseClient
    RS.Open "SELECT Surname FROM INT_PLAYER WHERE Category = 'Bowler'", Conn, adOpenDynamic

    Set DataCombo1.RowSource = RS
    DBCombo1.Text = ""
    DBCombo1.ListField = "Surname"
    DBCombo1.BoundColumn = ""


    I tried changing DataCombo1 to DBCombo1 incase it wasn't recognising the name but got different errors so assumed that wasn't the problem.

    I put the code into the main form part instead of having it in the 'DBcombo1' part.


    Thanx again for your help, u have no idea how much I need it!!!!

  11. #11
    Join Date
    Dec 2004
    Location
    Laguna, Philippines
    Posts
    147
    'oops sori...
    Set DataCombo1.RowSource = RS
    'should be...
    Set DBCombo1.RowSource = RS

    that correction should do the trick! but howcome errors occur? ive already tried the code and it runs perfectly.. what are the errors by the way?
    Give me a place to code and i shall move the earth!

  12. #12
    Join Date
    Mar 2005
    Posts
    27
    After changing it to "Set DBCombo1.RowSource = RS", I got the lovely 'Runtime error 91' again. Thought I saw the last of that error!

  13. #13
    Join Date
    Dec 2004
    Location
    Laguna, Philippines
    Posts
    147
    sori for the late reply.

    i just dont get it why error 91 occurs? is your db and recordset correctly setuped? what is the rest of your code?
    Give me a place to code and i shall move the earth!

Posting Permissions

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