Results 1 to 3 of 3

Thread: Another newbie with problems :)

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Posts
    79

    Question

    Hope someone out there can help me with this.

    I'm trying to write an application that will have to be using databases, although I can use Databases a little bit using Data Controls I'm stuck.

    In the database there will be two colomns, say x and y.

    Each record in column y will be a message, while column x will be the "Message ID". So each message will basically be numbered 1--->n.

    This particular form on my application will be used to update the database with new messages. There are 2 text boxes on the form, one will have the new Message ID and the other the new Message.

    When the form loads I want to open the database and move to the last record, I then want the application to take the last Message ID number i.e. the last entry in colomn x and add 1 to it and display the result in the textbox on the form corresponding to the next Message ID, this textbox has its Locked property set to True so it cannot be modified by the user.

    Once the Update button is clicked the Ne Message ID and Message will be added to the database.

    Here's what I have so far:

    General Declaration
    DIM BBDatabase As Database
    DIM CMessages AS Recordset


    Private Sub Form_Load()

    Set BBDatabase=OpenDatabase("C:\My Documents\BB.mdb")
    Set CMessages=BBDatabases.OpenRecordset("CMessages", dbOpendynaset)

    CMessages.MoveLast


    Don't know where to go from here though to Select the last Value of column x, the last used message ID.

    Anyone with any suggestions or better ways to do complete this please reply, have a feeling using SQL may help, but I've got an SQL Bible beside me and don't even know where to start

    Hope someone can help


    Cheers
    The problem with designing something completely foolproof is to underestimate the ingenuity of a complete fool. - Douglas Adams

    I know the human being and fish can coexist peacefully. - GWB

    I think we agree, the past is over. - GWB

  2. #2
    Addicted Member Michael Woolsey's Avatar
    Join Date
    Nov 2000
    Location
    Calgary, Alberta, Canada.
    Posts
    243
    I'm not quite sure what you're asking for, but I'll give it a shot anyway...

    You want to place the last record 'x' and 'y' in two text boxes on the screen...

    Code:
    Text1.Text = CMessages.Fields("x") + 1 'This sets the Textbox Text1 to the database value x. This assumes x is the last value in the database.
    Text2.Text = CMessages.Fields("y") 'This sets the Textbox Text2 to the database value y.
    Then you wish to update the database to include the new 'x' and 'y' values?

    Code:
    CMessages.AddNew
    CMessages.Fields("x") = CInt(Text1.Text) 'This gets the value from Textbox Text1.
    CMessages.Fields("y") = Text2.Text 'Assigns the value from the Textbox Text2 to y in the database.
    CMessages.Update
    Is this what you were looking for, or am I way off base? In MS Access (I don't know if you are using this) you may want to consider an autonumber for the field 'x'. This would automatically update to the next number in the sequence without having to manually change it.

    Hope this helps.
    Michael Woolsey
    Application/Web Developer

    Visual Basic 6.0 SP5
    Active Server Pages
    Oracle 9i
    - I'm going to live forever, or die trying!

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Posts
    79

    Question Thanks Michael!!

    i think you've bashed the nail right on the head

    I'll give this a go.

    I'll have a look at setting up an Autonumbr field in access, I think your right, it'll work better that way

    Don't worry I'll be back if I have more problems.


    Thanks again
    The problem with designing something completely foolproof is to underestimate the ingenuity of a complete fool. - Douglas Adams

    I know the human being and fish can coexist peacefully. - GWB

    I think we agree, the past is over. - GWB

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