How to make a log window from VBA

  • Thread starter Helge V. Larsen
  • Start date

H

Helge V. Larsen

I am developing an Access application where I am controlling a lot of
activity from VBA.
I would like to present a 'window' or form to the user that shows the
progress.
That is, I would like to be able to open a 'window', show some text, and (as
time goes by)
write some more lines at the bottom of the 'window'.
I would prefer not to have to let VBA send the text to a database table that
is referenced by the 'window',
but instead have VBA put the text directly into the 'window'.

How can I do this ?
 
Ad

Advertisements

R

Ron Weiner

Helge

If you had a form named frmLog that contained a unbound Text box txtLog then
as long as frmLog is loaded from anywhere in the app

Forms!frmLog.txtLog.value = Forms!frmLog.txtLog.value & "New text you want
to add." & vbcrlf

will append text to the text box.

Ron W
www.WorksRite.com
 
D

Dirk Goldgar

Ron Weiner said:
Helge

If you had a form named frmLog that contained a unbound Text box
txtLog then as long as frmLog is loaded from anywhere in the app

Forms!frmLog.txtLog.value = Forms!frmLog.txtLog.value & "New text
you want to add." & vbcrlf

will append text to the text box.

That's what I would do, too. I have a feeling you may have to do some
tweaking to make the text box scroll to the last item entered, once the
displayable area has been filled. You may have to set the focus to the
text box as part of that process, and I'm not sure you want to do that.
Of course, you could prepend the newest lines to the beginning of the
text box, instead of adding them at the end, but that might be
confusing.
 
K

Karl E. Peterson

Dirk said:
That's what I would do, too. I have a feeling you may have to do some
tweaking to make the text box scroll to the last item entered, once
the displayable area has been filled.

The trick is something like this:

txtLog.SelLength = 0
txtLog.SelStart = Len(txtLog.Text)
txtLog.SelText = NewTextString

That automatically scrolls to, and appends to, the end of whatever's already there.

Later... Karl
 
R

Ron Weiner

Yea - But Access aint VB.

In access before you can touch any of those text box properties you first
have to set focus to the text box so.....

txtLog.setFocus
txtLog.SelLength = 0
txtLog.SelStart = Len(txtLog.Text)
txtLog.SelText = "New text you want to add." & vbcrlf
' Optionally set the focus back to somewhere else

Ron W
www.WorksRite.com
 
R

Ron Weiner

Ooooppppsssss....

Actually

Forms!frmLog.txtLog.setFocus
Forms!frmLog.txtLog.SelLength = 0
Forms!frmLog.txtLog.SelStart = Len(txtLog.Text)
Forms!frmLog.txtLog.SelText = "New text you want to add." & vbcrlf

Ron W
www.WorksRite.com
 
Ad

Advertisements

D

Dirk Goldgar

Karl E. Peterson said:
The trick is something like this:

txtLog.SelLength = 0
txtLog.SelStart = Len(txtLog.Text)
txtLog.SelText = NewTextString

That automatically scrolls to, and appends to, the end of whatever's
already there.

That'll work, so long as the text box has the focus on that form. If
not, you can't reference the .Text or .Sel... properties. I was
interested to discover, though, that the text box doesn't have to have
the application's focus, just the form's focus. That means my worry
about setting focus to the log form was unnecessary. This version works
fine for me:

With Forms!frmLog!txtLog
.Value = (.Value + vbCrLf) & Time & " " & strMessage
.SetFocus
.SelStart = Len(.Text)
End With
 
K

Karl E. Peterson

Ron said:
Yea - But Access aint VB.

Oh Yeah? said:
In access before you can touch any of those text box properties you
first have to set focus to the text box so.....

txtLog.setFocus

Okay, whatever... "Some code left to the reader..." <bg>

Thanks... Karl
 
R

Ron Weiner

Helge

You need to add a DoEvents just after the End With in your sub
HVL_Log_Write. This will give the screen some time to repaint before having
to process the next command.

However I am curious as to why you are not using the standard Access text
box on your form. I would NOT recommend using the forms 2.0 text box Active
X control in an Access application unless you had a good reason to do so.

Ron W
 
H

Helge V. Larsen

To satisfy Ron's curiosity :
An Access TextBox can hold only a bit more than 2000 characters - as far as
I can see.
A Forms 2.0 TextBox seems to be able to hold any number of characters - and
this is important in a log window !

Helge
______________________________________
 
D

Douglas J. Steele

According to the Help file (under "Specifications, Access"), a text box can
hold 65,535 characters.
 
Ad

Advertisements

R

Ron Weiner

Hmmmm.....

Just did a quick test and find that I can not enter more than exactly 64,000
characters into either a unbound text box or a text box bound to a memo
field.

Until this very minute I thought that I could shovel several gigabytes of
stuff into a text box bound to a memo field. Doesn't make much sense to
have a database type capable of storing enormous amounts of data if the
interface does not support it.

One of these days I am gonna get bit in the butt on this one. I have one
app out there that makes extensive use of memo fields. It's only a matter of
time until one of our users calls with "I cant add more text to my [Enter
name of field here]" and I will have to re-factor that bad boy. Darn!!!
:-(
 
Ad

Advertisements

H

Helge V. Larsen

I have tested in more detail (on Microsoft Access 2000 (9.0.6926 SP-3)) :

Microsoft Access TextBox :
.TextBox.Text = S : Max length of S : 2.048
.TextBox.Value = S : Max length of S : 64.000

Microsoft Forms 2.0 TextBox :
.TextBox.Text = S : Max length of S : At least 1.020.000.
.TextBox.Value = S : Max length of S : At least 1.020.000.

64.000 is not enough for me. Therefore I have to use a Forms TextBox !

Helge
___________________________________________________

Ron Weiner said:
Hmmmm.....

Just did a quick test and find that I can not enter more than exactly
64,000
characters into either a unbound text box or a text box bound to a memo
field.

Until this very minute I thought that I could shovel several gigabytes of
stuff into a text box bound to a memo field. Doesn't make much sense to
have a database type capable of storing enormous amounts of data if the
interface does not support it.

One of these days I am gonna get bit in the butt on this one. I have one
app out there that makes extensive use of memo fields. It's only a matter
of
time until one of our users calls with "I cant add more text to my [Enter
name of field here]" and I will have to re-factor that bad boy. Darn!!!
:-(

--
Ron W
www.WorksRite.com
Douglas J. Steele said:
According to the Help file (under "Specifications, Access"), a text box can
hold 65,535 characters.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Top