Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    Apr 2001
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Code Problem (Access 2000)

    I need HELP!!!! This code is suppose to go through a list of employees and randomly choose the number that is specified. I am getting compiler errors where it starts: myset.[Selected] = True Then
    I am getting compiler errors with the word Selected. It does not recognize it. The problem is I am unsure what to put in its place. I just need some direction. Thanks in advance for any help.......Kristen


    Option Compare Database 'Use database order for string comparisons

    Private Sub Button30_Click()
    '***** Select each record using data specified on the form *****
    Call RECSELECT([TXT_NUMBER_OF_QUESTIONS])
    '***** Delete PRINT_TABLE Table *****
    DoCmd.SetWarnings off
    ' DoCmd DeleteObject A_TABLE, "PRINT_TABLE"
    DoCmd.OpenQuery "qryDeletePrintTable"
    '***** Populate the PRINT_TABLE with data from TEST Questions table *****
    DoCmd.SetWarnings off
    DoCmd.OpenQuery "qrySelectedEmployeesToPrint"

    End Sub

    Private Sub RECSELECT(rnum)
    If IsNull(rnum) = False Then
    rnum = Val(rnum)
    End If
    '***** Message to user *****
    Me![Label1].ForeColor = 255
    Label1.Caption = "Selecting Employees - Please wait...."

    If IsNull(rnum) Then
    Me![Label1].ForeColor = 0
    Label1.Caption = "Ready to view the results."
    Exit Sub
    End If

    '***** Forms Recordsource becomes a Query based on all records
    'Me.recordsource = "Test Questions QRY"
    Dim MyDB As Database, myset As Recordset
    Set MyDB = DBEngine.Workspaces(0).Databases(0)
    Set myset = MyDB.OpenRecordset("SELECT * FROM [CoteauEmployees]")
    myset.MoveLast
    DoEvents
    If myset.RecordCount < rnum Then
    MsgBox "There are only " & myset.RecordCount & " records "
    myset.Close
    DoEvents
    Exit Sub
    End If

    '***** Assign number of questions to a variable *****
    'Total = Val([txt_number_of_questions])
    TOTAL = Val(rnum)

    '***** Randomly select questions as long as at least one question matches criteria

    If myset.RecordCount > 0 Then
    no_of_query_records = myset.RecordCount
    Do
    '***** Select random number *****
    Randomize
    record_number = Int(no_of_query_records * Rnd + 1)

    '***** Go to the random record number *****


    myset.MoveFirst
    myset.Move record_number
    '***** Mark the record as Selected *****

    If myset.[Selected] = False Then
    myset.Edit
    myset.[Selected] = True
    myset.UPDATE
    HowManySelected = HowManySelected + 1
    End If


    Loop Until HowManySelected = TOTAL
    Else
    '***** if criteria query returned 0 then don't loop through random selection *****
    MsgBox "No questions found matching that criteria.", 16
    End If

    '***** User message *****
    Me![Label1].ForeColor = 0
    Label1.Caption = "Ready to view the Results."
    myset.Close
    End Sub

  2. #2
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Code Problem (Access 2000)

    I'm not up on any new properties introduced by Access2000, so does a recordset object have a "Selected" property? This is what you specified by using "myset.[Selected] = True"; you might try it without the brackets. If Selected is a field in the recordset, you want "myset!Selected = True".
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  3. #3
    New Lounger
    Join Date
    Apr 2001
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Code Problem (Access 2000)

    Okay I get a little confused with all of this. When I type in myset. I get a list of properties. Selected was not on there. I did what you mentioned and it works fine. Can you help me out with a why?????? Is this part of the Select function?????
    Thanks...............Kristen

  4. #4
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Code Problem (Access 2000)

    Don't confuse a recordset's Propertes with the Fields. For example, RecordCount is a property (you can use this to find out how many records are in the recordset). The fields contain the data. So, use a "." to denote properties (and methods), and a "!" to denote fields.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

Posting Permissions

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