CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2001
    Location
    Oregon, USA
    Posts
    12

    Saving User Entered Data

    ok first off i have a form with 3 textbox input areas. the user puts in the name of the script, the information to search for, and the response. they then hit the "add script" command button and it displays the name of the script (which they just specified) in a listbox. This also saves the information and response with it. the problem i have is that if the user closes that form then all the data is lost from it. i need some way to save the data they have entered to make it available for them later so they do not have to keep re-entering all the data fields. I am guessing that i need to keep a database file or a .ini of some sort, im not exactly sure. another thing which would be nice is when the user clicks on the script name in the listbox it displays the information in the 3 textbox fields that the user entered to make that script. im also not sure where to begin with that, i assume it also needs some sort of database. i think this just entails figuring out how to save input from a user after a form is closed, so it reappears when they open it again. if anyone can help on those 2 problems, that would be wonderful. i have been asking a few people on some programming channels (irc) and none of them have been able to help so far. thanks for taking the time to read this and possibly offer a solution or suggestion.

    -frank


  2. #2
    Join Date
    Sep 2001
    Location
    Oregon, USA
    Posts
    12

    Re: Saving User Entered Data

    ok i just figured out a cheap way of saving the data when they close the form (which isnt the main form), by just hiding it when they close, instead of unloading. i still need to save the data to a database for when they close the program completely to still save the entered data if anyone can help with that. thx,

    -frank


  3. #3
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Saving User Entered Data

    Here's what we will do, create a database in Access (or with the datadesigner), add a table called "Scripts", which has 3 columns (i will call them Column1, Column2 and Column3). Place the database is the same folder as the project. Add a ADO Control (ActiveX Data Objects control) to the form, you probably need to add it via the project>components menu.

    ' general declaration section
    private cnn as ADODB.Connection
    private rst as ADODB.Connection

    private Sub Form_Load()

    ' open connection to database
    set cnn = new ADODB.Connection
    cnn.provider = "Microsoft.Jet.OLEDB.4.0"
    cnn.open App.Path & "\scripts.mdb"

    ' open the recordset
    set rst = new ADODB.Recordset
    rst.Open "SELECT * FROM dbo_tblWerknemers", cnn, adOpenKeyset, adLockOptimistic

    ' bind the fields to the data control
    set Text1.DataSource = Adodc1
    set Text2.DataSource = Adodc1
    set Text3.DataSource = Adodc1

    ' vind the fields to a specific field
    Text1.DataField = "Column1"
    Text2.DataField = "Column2"
    Text3.DataField = "Column3"

    ' finally, attch recordset to control
    set Adodc1.Recordset = rst

    End Sub



    What this code does is it opens a recordset, and binds it to the form. This way, you don't need to do the saving and loading stuff yourself. You can see that by pressing the datacontrol, you cannavigate through the recordset, without any code.

    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  4. #4
    Join Date
    Sep 2001
    Location
    Oregon, USA
    Posts
    12

    Re: Saving User Entered Data

    thanks, i will have to install Access tomorrow and will try out your suggestion, looks like it should work for what i need. Thanks a bunch for the info

    (will post tomorrow sometime letting you know if it works out as it should)

    -frank


  5. #5
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Saving User Entered Data

    The Visual Datamanager is supplied with VB, which can also be used to create the database, this doesn't require you to install Access. It can be found in the Add-ins Menu.

    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  6. #6
    Join Date
    Sep 2001
    Location
    Oregon, USA
    Posts
    12

    Re: Saving User Entered Data

    ok I found the DataManager, but I dont understand how that works. I am more familiar with Access. I don't even see a place to add tables using the DM, lol. I've never even seen that before. Oh well, I will just try it with Access, I think that it will work once I install and make the .mdb. thanks for the help,

    -frank


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

Featured