Results 1 to 8 of 8

Thread: Recordset problem

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2003
    Posts
    18

    Recordset problem

    I am creating a DB and table etc. on the fly but in the function that I ma testing to see if the user is in the DB it bombs out! It throws an error: "Object variable or block varialbe not set"

    Any ideas?


    'Creating DB on the fly......

    Dim cat As New ADOX.Catalog

    'create an Access 97 Database
    cat.Create "Provider=Microsoft.Jet.OLEDB.3.51;" & "Data Source=" & App.Path & ".\mydata.mdb"

    'DB is locked until cat object is released
    Set cat = Nothing
    '
    Dim con As ADODB.Connection
    Dim cmd As ADODB.Command
    Dim sSql As String

    'Open connection to the new db
    Set con = New ADODB.Connection
    con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51;Data Source=" & App.Path & ".\mydata.mdb;Persist Security Info=false"
    con.Open



    'run Sql query to create table
    Set cmd = New ADODB.Command
    cmd.ActiveConnection = con
    sSql = "CREATE TABLE Students (LoginID TEXT (50), Password TEXT (50), FirstName TEXT (50), LastName TEXT (50), Department TEXT (50),"
    sSql = sSql & "CONSTRAINT MyFieldConstraint PRIMARY KEY(LoginID, Password));"

    ....................................................................

    'called in another function
    If FindUser(sUserID, sPassword) = True Then
    'change where am i
    sWhereAmI = "DISPLAYUSER"
    Else
    iResult = MsgBox("There are no users with the ID and Password you entered, Would you like to add them", vbYesNo + vbQuestion, "Log In")
    End If

    ...........................................................................
    'called by the above code

    Function FindUser(sUserName As String, sUserPW As String) As Boolean
    Data1.Recordset.Index = "MyFieldConstraint"
    Data1.Recordset.Seek "=", sUserName, sUserPW
    'So that No match = True
    FindUser = Not Data1.Recordset.NoMatch

    End Function

  2. #2
    Hyperactive Member
    Join Date
    Aug 2002
    Posts
    416
    you need a 'set something = new something' somewhere :\

  3. #3

    Thread Starter
    Junior Member
    Join Date
    May 2003
    Posts
    18
    Sorry not following that...

  4. #4
    Frenzied Member andreys's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,615
    On what line you are getting this error?

  5. #5

    Thread Starter
    Junior Member
    Join Date
    May 2003
    Posts
    18
    Data1.Recordset.Index = "MyFieldConstraint"

  6. #6
    Frenzied Member andreys's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,615
    Make sure that "MyFieldConstraint" is an index in the table that you searching.
    One more thing. The "Seek" method works only if RecordsetType is a Table (0). So try this:
    VB Code:
    1. Function FindUser(sUserName As String, sUserPW As String) As Boolean
    2.  
    3. With Data1
    4.    .DatabaseName = Path_To_The_Database_here
    5.    .RecordSource = Table_Name_Here
    6.    .RecordsetType = 0 'Table
    7.    .Refresh
    8.    .Recordset.Index = "MyFieldConstraint"
    9.    .Recordset.Seek "=", sUserName, sUserPW
    10.    'So that No match = True
    11.    FindUser = Not  .Recordset.NoMatch
    12. End With
    13.  
    14. End Function

  7. #7

    Thread Starter
    Junior Member
    Join Date
    May 2003
    Posts
    18
    Thanks that seems to work!

  8. #8
    Frenzied Member andreys's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,615
    Just ouit of curiosity. Why do you use DataControl to verify user?
    You are already using ADO in your program.
    I suggest to you this way. Make separate fields UserName and UserPassword within User table, then just use this
    VB Code:
    1. Function FindUser(sUserName As String, sUserPW As String) As Boolean
    2. Dim rs, strSQL, conn
    3.  
    4.    conn="Provider=Microsoft.Jet.OLEDB.3.51;" & "Data Source=" & App.Path & ".\mydata.mdb"
    5.    strSQL="SELECT * FROM [User] WHERE [UserName]='" & sUserName & "' AND UserPAssword='" & sUserPW & "'"
    6.    
    7.    Set rs = CreateObject("ADODB.Recordset")
    8.    rs.open strSql, conn
    9.    FindUser = Not  rs.EOF
    10.    rs.Close
    11.    Set rs = Nothing
    12.  
    13. End Function

Posting Permissions

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



Click Here to Expand Forum to Full Width