Solved

Load Settings from txt file

Posted on 2003-11-19
5
301 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
  • 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 50 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need VBS version of Excel date conversion 4 71
Using "ScreenUpdating" 6 65
Visual Studio search word table and return Cell index 8 61
TT Auto Dashboard 13 92
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

777 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