visible / lock - Possible?

hrov

Registered User.
Local time
Today, 02:30
Joined
Feb 18, 2009
Messages
52
Is this even possible?

I have a date entry textbox on my form. I also have a "insert time" textbox aswell. Can I either lock, or make the "insert time" box invisible if the date entered in the first box is after todays date?
 
Yes try the following; in the After Update event of your Date entry field, You will also need to put it in the Form's On Current event;

Code:
If Me.DateEnter.Value > Date() then
     Me.TimeInsert.Visible = False
Else
     Me.TimeInsert.Visible = True
End If
 
Or if you want to get real "efficient" with the code:

Code:
Me.TimeInsert.Visible = Not (Me.DateEnter.Value > Date())
 
Yes try the following; in the After Update event of your Date entry field, You will also need to put it in the Form's On Current event;

Code:
If Me.DateEnter.Value > Date() then
     Me.TimeInsert.Visible = False
Else
     Me.TimeInsert.Visible = True
End If
Wonderful :)
 
Bob, your code is very simple, but I'm just having a little trouble understanding exactly how it is working. Could you possibly explain the the structure of the statement.
 
Bob, your code is very simple, but I'm just having a little trouble understanding exactly how it is working. Could you possible explain the the structure of the statement.

Sure thing -

We are looking for a True or False for the Visible property, correct?

Me.TimeInsert.Visible is either True or False

The statement

Me.DateEnter.Value > Date()

will either be True or False so we can use that to our advantage.

By encapsulating it in parens, we now can use the resulting value of True or False and since the VISIBLE property is inverse of the value of that statement (we want it visible if the value is false and hidden if true), we use the NOT keyword to reverse the value for our .Visible property.

Does that help?
 
the operator "Not" is logical negation. Thus Bob's code evaluates if Date entered is in future, which then is negated and thus applied to Visible:

For example:

.Visible = Not (3/20/2009 > 3/19/2009)
.Visible = Not (True)
.Visible = False

PS Bob is not only faster typist but much more verbose! :)
 
So I suppose you're saying you make it up by doing 4 lines of comment per statement in your code? ;)
 
So I suppose you're saying you make it up by doing 4 lines of comment per statement in your code? ;)

Could be, could be...

smiley.jpg
 
Thanks Guys that makes perfect sense. I had just never come across that structure before.
 
Thanks Guys that makes perfect sense. I had just never come across that structure before.
thanks for your help again

But when the user is faced with a blank form is it possible to hide the "time" text?
This would mean that the time text box would only become visble after the date textbox had been filled in and is less than todays date.

Code:
Private Sub Form_Current()
If Me.EnterDate.Value > Date 
Or = ""    Then
     Me.EnterTime.Visible = False
    
Else
Me.EnterTime.Visible = True

I know this is wrong because it isnt working, (wheras it was before i tried to change it to or "".)
 
If you want to hide the time textbox by default for new record, use OnCurrent event:

Code:
Me.EnterTime.Visible = Not Me.NewRecord

If you want to account for possibility of nulls or blanks in your date without error, then Try this:

Code:
Me.EnterDate.Visible = Not (Nz(Me.EnterDate, 0) > Date())
 
two other points about this, and some further meanderings on bitwise operations, and encryption

some of the identifiers (me. for instance are implicit, and .value)
and you often need to allow for a blank date field, so you need an nz as well

so you could get this which also includes testing for a blank date (which is treated as visible in this case - since 0 will always be less than todays date)

TimeInsert.Visible = Not (nz(DateEnter,0) > Date())

-----------
with regard to boolean operations, bitwise operations on numbers are also strange beasts to understand

look at the dir function in conjunction with getattr function and then see

'use dir to get a file from a given path
FNAME = DIR(SOMEPATH)

'now the file attribute include things like readonly, archived, directory etc
'so do a boolean AND (mask) with the attribute you REALLY want to test

If (GetAttr(SOMEpath & fname) And vbDirectory) = vbDirectory Then

this masks the actually attribute, which is a number in the range 1 - 127, with the number for a directory which is 16.

the binary represnation of 16 is

00001000

so say the file attribute is
01001100

then ANDing thiese two numbers

00001000
01001100

00001000, returns 1 in the positions only where the bits are both 1

so if this file is a directory/folder the boolean AND returns just 00001000 ie 16, and if its not it returns 0

hence comparing the result with what you were searching for is eaither true or false

effectively

if (retrievednumber AND searchedforbit) = searchedforbit then true

---------------
one other simple use for boolean bitwise operations is simple encryption

take any string and mask each byte using the boolean XOR operation

effectively (although you cannot slice strings in quite this way with vba - why no char data type - such a loss)

Code:
for each char in string
  char = char xor anyvalue
next

generates a meaningless encrypted string

but the interesting thing about XOR is that it is reversible, so given the encrypted string

Code:
for each char in string
  char = char xor anyvalue
next

gives the original string.

This is quite useful for a bot of casual encryption of passwords etc.

just have a function called

Code:
function encrypt(s as string) as string
 return result by XOR ing each char with any given byte
end function

call once to encrypt - call again for the plaintext
 

Users who are viewing this thread

Back
Top Bottom