Save UserForm Data

Discussion in 'AutoCAD' started by geotis, Dec 31, 2004.

  1. geotis

    geotis Guest

    Is there a way to save the ListBox values entered at run time in the UerForm after it's unloaded?

    TIA
     
    geotis, Dec 31, 2004
    #1
  2. Any database[or txt file] will do... Don't think there is anything
    built in...gl
     
    Paul Richardson, Dec 31, 2004
    #2
  3. geotis

    geotis Guest

    Paul,

    Thanks for your reply.

    Maybe I need to clarify the question.

    I fill in the UserForm ListBoxes with text file data at run time, but after unloading the UserForm, I don't know how to save the text file data in the UserForm.
     
    geotis, Dec 31, 2004
    #3
  4. How are you getting the data from the text file into the listbox? Show us
    the code and we can probably show you a reverse process.
    --
    John Goodfellow
    irtfnm
    use john at goodfellowassoc dot com


    after unloading the UserForm, I don't know how to save the text file data in
    the UserForm.
     
    John Goodfellow, Dec 31, 2004
    #4
  5. geotis

    geotis Guest

    Sorry, it's TextBoxes with the data, not ListBoxes.

    A 1x70 array of TextBoxes (sBox) is filled with a 10x7 array of Doubles (Soil(I,J)) that are Input from a text file:

    Public Soil(1 To 10, 1 To 7) As Double, sBox(1 To 70) As TextBox
    Sub SoilDataData(Soil, sBox)

    Set sBox(1) = frmSoilData.TextBox1
    Set sBox(2) = frmSoilData.TextBox2...
    ..
    ..
    Set sBox(70) = frmSoilData.TextBox70

    N = 0
    For I = 1 To 10
    For J = 1 To 7
    N = N + 1
    sBox(N).Value = Soil(I, J)
    Next J
    Next I

    So, how do I save these arrays in the UserForm (frmSoilData) after the form is Unloaded?

    Thanks
     
    geotis, Dec 31, 2004
    #5
  6. geotis

    geotis Guest

    Sorry again...

    How do I 'Save' the sBox(1 To 70).Values in frmSoilData?
     
    geotis, Dec 31, 2004
    #6
  7. John's suggenstion will get you a closer response...
    but here is the idea...

    Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    Dim nFile1 As Integer: nFile1 = FreeFile
    Dim oControl As Control
    'Create New file
    Open "c:\Temp.txt" For Output As #nFile1
    For Each oControl In UserForm1.Controls
    Print #nFile1, oControl.Name & vbTab & oControl.Value
    Next oControl
    Close #nFile1
    'Delete original and rename Temp
    VBA.Kill ("c:\FileControlsWereLoadedFrom.txt")
    Name "c:\Temp.txt" As "C:\FileControlsWereLoadedFrom.txt"
    End Sub

    gl

    Paul
     
    Paul Richardson, Dec 31, 2004
    #7
  8. geotis

    geotis Guest

    I have failed to convey my question.

    TheTextBox controls in the UserForm contain default data before run time, then are filled with new data at run time... how do I retain the new data in the UserForm controls after the UserForm is Unloaded?

    Bruce Smith
     
    geotis, Jan 1, 2005
    #8
  9. Check out the thread "Can VBA code write to itself"
     
    Paul Richardson, Jan 1, 2005
    #9
  10. geotis

    geotis Guest

    I will do that, but I did accomplish what I need to do by Hiding the form and not Unloading it, this keeps the data in memory.

    Thanks
     
    geotis, Jan 1, 2005
    #10
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.