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?
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.
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.
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 "".)
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