Results 1 to 8 of 8

Thread: Absoluterecord - Why doesn't this work?

  1. #1

    Thread Starter
    Hyperactive Member Sal's Avatar
    Join Date
    Mar 2000
    Posts
    262
    Why doesn't this work?

    Dim CurrentRecord As Integer
    CurrentRecord = (Data1.Recordset.AbsolutePosition + 1)
    Select Case CurrentRecord
    Case 2
    lblAnswerA.Caption = "multi-1"
    lblAnswerB.Caption = "multi-3"
    end select

  2. #2
    Fanatic Member
    Join Date
    Jan 1999
    Location
    UK
    Posts
    554
    Hi,

    I'm just starting out on databases myself, but from i gather when no record is selected then the value of absolute record is -1 similar to a listbox or combobox

    DocZaf
    {;->

    ps i may be wrong, so dont quote me
    :-)

  3. #3
    Member
    Join Date
    Jan 1999
    Posts
    41
    it is hard to understand what exactly you are doing.
    Do you want to post more specific information or e-mail it to me if feel uncomfortable posting it?

  4. #4

    Thread Starter
    Hyperactive Member Sal's Avatar
    Join Date
    Mar 2000
    Posts
    262
    Gathering info...standby

  5. #5

    Thread Starter
    Hyperactive Member Sal's Avatar
    Join Date
    Mar 2000
    Posts
    262
    Project:
    Create a program that has questions with muliple-choice answers.

    Tools: VB and MSAccess

    Step-1:

    I used MSAccess to create a database of questions and answers. There are four multiple-choice answers. There is only one correct answer. The database has fields containing these questions and answers. The database's field names are - question(this is the actual question), multi-1, multi-2, multi-3(all of these are the multiple choice answers), and answer(this field in my Access database contains the correct answer).

    Step-2:

    I used VB to display the questions by binding a control to the MSAccess Database containing the questions. I have a Label called lblQuestion which is bound to my MSAccess database. lblQuestion's bound datafield is question from the actual database. I also have four labels in VB named multi-1, multi-2, multi-3, and multi-4, obviously for the multiple choice answers, of which only one will be correct.

    Step-3

    Each time the user moves the record, the next question will appear. My problem is this: I could simply bind the multiple-choice labels in VB to the database, but they would stay in the same order for each question. This is a problem because the correct answer would always be say for example "C", so then there would be no challenge to finding the correct answer.

    Concept:

    For record 1 have the following:
    lblMulti-1.datafield = say my database multiple-choice answer4
    lblMulti-2.datafield = say multiple-choice answer3
    lblMulti-3.datafield = say the correct answer

    ...and so on This is question 1

    Then for record 2 same as question 2 for the user...
    lblMulti-1.datafield = now the correct answer
    lblMulti-2.datafield = say the database multiple-choice answer4
    I'm basically changing the multiple-choice answer order from my database.

    ****** Missing Link ***************
    How do I tell the program(VB) that we are now looking at record 2, and then record 3 and so on.
    **************************************

    I thought I could simply go in and get the value of the currentrecord by using either data1.recordset.value, that didn't work. Then I tried, data1.recordset.fields("ID"), using the ID field from the Access autonumber database, that didn't work. Then finally,...absoluteposition. That didn't work. Maybe it's my syntax.

    ************************************************************
    Here is my latest attempt:

    Public Sub AbsoluteRecord()

    Dim CurrentRecord As Integer
    CurrentRecord = (Data1.Recordset.AbsolutePosition + 1)

    Select Case CurrentRecord

    Case Is = 1
    lblAnswerA.DataField = "multi-2"
    lblAnswerB.DataField = "multi-1"
    lblAnswerC.DataField = "answer"
    lblAnswerD.DataField = "multi-3"

    Case Is = 2
    lblAnswerA.DataField = "multi-3"
    lblAnswerB.DataField = "multi-2"
    lblAnswerC.DataField = "multi-1"
    lblAnswerD.DataField = "answer"

    End Select
    ************************************************************

  6. #6

    Thread Starter
    Hyperactive Member Sal's Avatar
    Join Date
    Mar 2000
    Posts
    262
    .

  7. #7
    Member
    Join Date
    Jan 1999
    Posts
    41
    Try my example. I want to be sure that we are on the same page.
    Do you have Northwind database?
    Open new vb project. Put data control and text box on a form. Erase Caption property for data control and text property for a text box.
    Copy code below on a form:

    Option Explicit
    Dim ws As Workspace
    Dim db As Database
    Dim rs As Recordset

    Private Sub Data1_Reposition()
    ' Used to identify current record
    Data1.Caption = rs.AbsolutePosition
    Text1 = rs.Fields("CustomerID")
    End Sub

    Private Sub Form_Load()
    'Used to open a table in a database and set absolute position
    Set db = Workspaces(0).OpenDatabase("C:\Program Files\Microsoft Office\Office\Samples\Northwind.mdb")
    Set rs = db.OpenRecordset("Select * From Orders Order By OrderID")
    Set Data1.Recordset = rs

    Data1.Caption = rs.AbsolutePosition
    End Sub

    Is that kind of what you want? Please, let me know.




  8. #8

    Thread Starter
    Hyperactive Member Sal's Avatar
    Join Date
    Mar 2000
    Posts
    262

    That Works!!! Lana for VB President

    Lana,

    You are a genius. How does this work. I will post the response online so that others can benefit from your knowledge.

    Specific questions:

    1) I have a database control on my form that already has the database name. Do I still need to tell the program in code what the name of my database is, although the name is in the database control property box?

    2) What is the purpose of workspaces(0)

    3) Why do you have to dim db as database, can't you just say database? I ask because I don't know.

    4) What is the purpose of those set statements? Especially "set data1.recordset = rs"

    5) Why does Data1.caption = rs.AbsolutePosition appear twice in the code?

    Have a lot to learn,
    Sal
    (I already knew that though)

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