What's wrong with this code?

S

Sue Compelling

Hi

I have the following code which works perfectly when a user selects "1"
though does not work for when they select "10" ... what have I done wrong? ...

My code is ...

Private Sub Form_Current()

Me![contactsorg subform].Form.Visible = False = (Me.Type = 1) or (Me.Type =
10)
Me.Org_NameLabel.Visible = False = (Me.Type = 1) or (Me.Type = 10)
Me.OName.Visible = False = (Me.Type = 1) or (Me.Type = 10)
Me.OrgContacts_Label.Visible = False = (Me.Type = 1) or (Me.Type = 10)
Me.Website.Visible = False = (Me.Type = 1) or (Me.Type = 10)
Me.Website_Label.Visible = False = (Me.Type = 1) or (Me.Type = 10)
--


TIA


Sue Compelling
 
S

Stuart McCall

Sue Compelling said:
Hi

I have the following code which works perfectly when a user selects "1"
though does not work for when they select "10" ... what have I done wrong?
...

My code is ...

Private Sub Form_Current()

Me![contactsorg subform].Form.Visible = False = (Me.Type = 1) or (Me.Type
=
10)
Me.Org_NameLabel.Visible = False = (Me.Type = 1) or (Me.Type = 10)
Me.OName.Visible = False = (Me.Type = 1) or (Me.Type = 10)
Me.OrgContacts_Label.Visible = False = (Me.Type = 1) or (Me.Type = 10)
Me.Website.Visible = False = (Me.Type = 1) or (Me.Type = 10)
Me.Website_Label.Visible = False = (Me.Type = 1) or (Me.Type = 10)
--


TIA


Sue Compelling

Lose the '= False' from each line.
 
O

OssieMac

Hi Sue,

The following 2 examples of code should explain it for you. Basically you
want to equate to True or False. The second example shows how to obtain the
opposite result.

'Example 1. Equates to True if Me.Type is 1 or 10
MsgBox "Me.Type = " & Me.Type & Chr(13) & _
"Result = " & ((Me.Type = 1) Or (Me.Type = 10))

Me.Text1.Visible = ((Me.Type = 1) Or (Me.Type = 10))
Me.Text2.Visible = ((Me.Type = 1) Or (Me.Type = 10))
Me.Text3.Visible = ((Me.Type = 1) Or (Me.Type = 10))

'Example 2. Equates to False if Me.Type is 1 or 10
MsgBox "Me.Type = " & Me.Type & Chr(13) & _
"Result = " & Not ((Me.Type = 1) Or (Me.Type = 10))

Me.Text1.Visible = Not ((Me.Type = 1) Or (Me.Type = 10))
Me.Text2.Visible = Not ((Me.Type = 1) Or (Me.Type = 10))
Me.Text3.Visible = Not ((Me.Type = 1) Or (Me.Type = 10))
 
S

Sue Compelling

Brilliant Stuart - that worked perfectly for existing records.

Is there a way I can stop the "Runtime Error 13 - type mismatch" happening
when I go to add a new record with this code (I think it's something to do
with the subform?)

--
Sue Compelling


Stuart McCall said:
Sue Compelling said:
Hi

I have the following code which works perfectly when a user selects "1"
though does not work for when they select "10" ... what have I done wrong?
...

My code is ...

Private Sub Form_Current()

Me![contactsorg subform].Form.Visible = False = (Me.Type = 1) or (Me.Type
=
10)
Me.Org_NameLabel.Visible = False = (Me.Type = 1) or (Me.Type = 10)
Me.OName.Visible = False = (Me.Type = 1) or (Me.Type = 10)
Me.OrgContacts_Label.Visible = False = (Me.Type = 1) or (Me.Type = 10)
Me.Website.Visible = False = (Me.Type = 1) or (Me.Type = 10)
Me.Website_Label.Visible = False = (Me.Type = 1) or (Me.Type = 10)
--


TIA


Sue Compelling

Lose the '= False' from each line.
 
S

Sue Compelling

Thanks OssieMac for the breakdown - Cheers
--
Sue Compelling


OssieMac said:
Hi Sue,

The following 2 examples of code should explain it for you. Basically you
want to equate to True or False. The second example shows how to obtain the
opposite result.

'Example 1. Equates to True if Me.Type is 1 or 10
MsgBox "Me.Type = " & Me.Type & Chr(13) & _
"Result = " & ((Me.Type = 1) Or (Me.Type = 10))

Me.Text1.Visible = ((Me.Type = 1) Or (Me.Type = 10))
Me.Text2.Visible = ((Me.Type = 1) Or (Me.Type = 10))
Me.Text3.Visible = ((Me.Type = 1) Or (Me.Type = 10))

'Example 2. Equates to False if Me.Type is 1 or 10
MsgBox "Me.Type = " & Me.Type & Chr(13) & _
"Result = " & Not ((Me.Type = 1) Or (Me.Type = 10))

Me.Text1.Visible = Not ((Me.Type = 1) Or (Me.Type = 10))
Me.Text2.Visible = Not ((Me.Type = 1) Or (Me.Type = 10))
Me.Text3.Visible = Not ((Me.Type = 1) Or (Me.Type = 10))


--
Regards,

OssieMac


Sue Compelling said:
Hi

I have the following code which works perfectly when a user selects "1"
though does not work for when they select "10" ... what have I done wrong? ...

My code is ...

Private Sub Form_Current()

Me![contactsorg subform].Form.Visible = False = (Me.Type = 1) or (Me.Type =
10)
Me.Org_NameLabel.Visible = False = (Me.Type = 1) or (Me.Type = 10)
Me.OName.Visible = False = (Me.Type = 1) or (Me.Type = 10)
Me.OrgContacts_Label.Visible = False = (Me.Type = 1) or (Me.Type = 10)
Me.Website.Visible = False = (Me.Type = 1) or (Me.Type = 10)
Me.Website_Label.Visible = False = (Me.Type = 1) or (Me.Type = 10)
--


TIA


Sue Compelling
 
O

OssieMac

Pleased to help Sue. On the question in your reply to Stuart. That error is
normally due to incorrect data type. Quote from help: For example, a variable
that requires an integer value can't accept a string value unless the whole
string can be recognized as an integer.

However, I have previously seen incorrect error messages for the actual
error so ensure that it is not a Null value causing the problem. Try the Nz
function in conjunction with Me.Type so that it will equate to zero in lieu
of Null. See help for more info if you are not familiar with it.

Example
Me.Text1.Visible = ((Nz(Me.Type,0) = 1) Or (Nz(Me.Type,0) = 10))
--
Regards,

OssieMac


Sue Compelling said:
Thanks OssieMac for the breakdown - Cheers
--
Sue Compelling


OssieMac said:
Hi Sue,

The following 2 examples of code should explain it for you. Basically you
want to equate to True or False. The second example shows how to obtain the
opposite result.

'Example 1. Equates to True if Me.Type is 1 or 10
MsgBox "Me.Type = " & Me.Type & Chr(13) & _
"Result = " & ((Me.Type = 1) Or (Me.Type = 10))

Me.Text1.Visible = ((Me.Type = 1) Or (Me.Type = 10))
Me.Text2.Visible = ((Me.Type = 1) Or (Me.Type = 10))
Me.Text3.Visible = ((Me.Type = 1) Or (Me.Type = 10))

'Example 2. Equates to False if Me.Type is 1 or 10
MsgBox "Me.Type = " & Me.Type & Chr(13) & _
"Result = " & Not ((Me.Type = 1) Or (Me.Type = 10))

Me.Text1.Visible = Not ((Me.Type = 1) Or (Me.Type = 10))
Me.Text2.Visible = Not ((Me.Type = 1) Or (Me.Type = 10))
Me.Text3.Visible = Not ((Me.Type = 1) Or (Me.Type = 10))


--
Regards,

OssieMac


Sue Compelling said:
Hi

I have the following code which works perfectly when a user selects "1"
though does not work for when they select "10" ... what have I done wrong? ...

My code is ...

Private Sub Form_Current()

Me![contactsorg subform].Form.Visible = False = (Me.Type = 1) or (Me.Type =
10)
Me.Org_NameLabel.Visible = False = (Me.Type = 1) or (Me.Type = 10)
Me.OName.Visible = False = (Me.Type = 1) or (Me.Type = 10)
Me.OrgContacts_Label.Visible = False = (Me.Type = 1) or (Me.Type = 10)
Me.Website.Visible = False = (Me.Type = 1) or (Me.Type = 10)
Me.Website_Label.Visible = False = (Me.Type = 1) or (Me.Type = 10)
--


TIA


Sue Compelling
 
S

Stuart McCall

Sue Compelling said:
Brilliant Stuart - that worked perfectly for existing records.

Is there a way I can stop the "Runtime Error 13 - type mismatch" happening
when I go to add a new record with this code (I think it's something to
do
with the subform?)
<snip>

Surround your code with a test for the new record being current, like this:

If Not Me.NewRecord Then

'Your code here

End If

So the code will now only execute when an existing record is current.
 
S

Sue Compelling

Thanks OssieMac for following through ... I did Stuart's trick and it worked
a charm ... cheers
--
Sue Compelling


OssieMac said:
Pleased to help Sue. On the question in your reply to Stuart. That error is
normally due to incorrect data type. Quote from help: For example, a variable
that requires an integer value can't accept a string value unless the whole
string can be recognized as an integer.

However, I have previously seen incorrect error messages for the actual
error so ensure that it is not a Null value causing the problem. Try the Nz
function in conjunction with Me.Type so that it will equate to zero in lieu
of Null. See help for more info if you are not familiar with it.

Example
Me.Text1.Visible = ((Nz(Me.Type,0) = 1) Or (Nz(Me.Type,0) = 10))
--
Regards,

OssieMac


Sue Compelling said:
Thanks OssieMac for the breakdown - Cheers
--
Sue Compelling


OssieMac said:
Hi Sue,

The following 2 examples of code should explain it for you. Basically you
want to equate to True or False. The second example shows how to obtain the
opposite result.

'Example 1. Equates to True if Me.Type is 1 or 10
MsgBox "Me.Type = " & Me.Type & Chr(13) & _
"Result = " & ((Me.Type = 1) Or (Me.Type = 10))

Me.Text1.Visible = ((Me.Type = 1) Or (Me.Type = 10))
Me.Text2.Visible = ((Me.Type = 1) Or (Me.Type = 10))
Me.Text3.Visible = ((Me.Type = 1) Or (Me.Type = 10))

'Example 2. Equates to False if Me.Type is 1 or 10
MsgBox "Me.Type = " & Me.Type & Chr(13) & _
"Result = " & Not ((Me.Type = 1) Or (Me.Type = 10))

Me.Text1.Visible = Not ((Me.Type = 1) Or (Me.Type = 10))
Me.Text2.Visible = Not ((Me.Type = 1) Or (Me.Type = 10))
Me.Text3.Visible = Not ((Me.Type = 1) Or (Me.Type = 10))


--
Regards,

OssieMac


:

Hi

I have the following code which works perfectly when a user selects "1"
though does not work for when they select "10" ... what have I done wrong? ...

My code is ...

Private Sub Form_Current()

Me![contactsorg subform].Form.Visible = False = (Me.Type = 1) or (Me.Type =
10)
Me.Org_NameLabel.Visible = False = (Me.Type = 1) or (Me.Type = 10)
Me.OName.Visible = False = (Me.Type = 1) or (Me.Type = 10)
Me.OrgContacts_Label.Visible = False = (Me.Type = 1) or (Me.Type = 10)
Me.Website.Visible = False = (Me.Type = 1) or (Me.Type = 10)
Me.Website_Label.Visible = False = (Me.Type = 1) or (Me.Type = 10)
--


TIA


Sue Compelling
 

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