Solved

Load Settings from txt file

Posted on 2003-11-19
5
304 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 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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Best way to parse out a json string in VB6? 10 386
Using "ScreenUpdating" 6 85
Recommendation vb6 to vb.net or others 14 240
clicking a shape in a frame array vb6 3 54
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

732 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