?
Solved

Load Settings from txt file

Posted on 2003-11-19
5
Medium Priority
?
307 Views
Last Modified: 2010-05-03
Hi All,
I have been working with a Excel Macro. Here i have a form which has the following controls:
CheckBox1
CheckBox2
CheckBox3
CheckBox4
Option1
Option2

My macro form has a CommandButton which when pressed loads the settings from a text file to the controls.

However, I want the settings to load to the form atomatically as soon as the form is loaded without the need of pressing the button.

Please can someone help me in this. I am giving the macro code herewith.

Private fso As New FileSystemObject
Private strm As TextStream
Private strName As String

Private Sub Button_Click()
    GetSettings "C:\Settings.txt"
End Sub

Private Sub GetSettings(ByVal FileName As String)
    Set strm = fso.OpenTextFile(FileName, ForReading)
    With strm
        CheckBox1.Value = .ReadLine
        CheckBox2.Value = .ReadLine
        CheckBox3.Value = .ReadLine
        CheckBox4.Value = .ReadLine
        Option1.Value = .ReadLine
        Option2.Value = .ReadLine
        .Close
    End With
End Sub
Thanks in advance,
LonelySoul
0
Comment
Question by:LonelySoul
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 9

Expert Comment

by:TooKoolKris
ID: 9779715
Is there not a Sub for Form_Load or anything like that to play with. There has to be an event that fires when the form loads you need to determine what this is and how to manipulate it.
0
 
LVL 29

Accepted Solution

by:
leonstryker earned 200 total points
ID: 9779745
LonelySoul,

You can use UserForm_Activate event to fire your code.

Private Sub UserForm_Activate()
    GetSettings "C:\Settings.txt"
End Sub


This will load your settings then the form is activated
Leon
0
 
LVL 9

Expert Comment

by:TooKoolKris
ID: 9779996
See I told ya there was something, just forgot what it was called.

Thanks Leonstryker
0
 

Author Comment

by:LonelySoul
ID: 9785282
Hi leonstryker and ToolKoolChris,
Thanks for the answer
LonelySoul
0
 
LVL 29

Expert Comment

by:leonstryker
ID: 9786899
Thanks for the grade.

Leon
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question