-
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
-
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
-
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