473,804 Members | 2,931 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MS Access: Using the IIf Function in a form

Hello,
I am designing a form and need to know how to get a Check Box(PASS)to
automatically update when the data in a Text Box (MARK), in the same
form, is >=24.
Using the Event dialogue box for the Check Box, AfterUpdate, I have
tried:
IIf([MARK]>=24,True,False )
Also:
IIf([MARK]>=24,1,0)
Also:
IIf([MARK]>=24,"Yes","No" )

Although I get no error messages, nothing seems to work.
Any suggestions?
Nov 12 '05
16 11173
Ji****@NOTdatac entricsolutions .com (Jim Allensworth) wrote in message news:<3f******* ******@netnews. comcast.net>...
On Sun, 23 Nov 2003 15:26 +0000 (GMT Standard Time), ru***@127.0.0.1
(Peter Russell) wrote:
Phil Stanton previously wrote:
Private Sub MARK_AfterUpdat e()

If me.MARK >= XXXXX Then 'what?
me.Pass = True
Else
me.Pass = False
End If

End Sub

Or simply...
Private Sub MARK_AfterUpdat e()
Me.PASS = Me.MARK >= 24
End Sub

- Jim


Jim, Tried this one first:

Private Sub Mark_AfterUpdat e()
If Me.MARK >= 24 Then
Me.Pass = True
Else
Me.Pass = False
End If
End Sub

This had no effect and showed no errors. So I tried the second one as follows:

Private Sub Mark_AfterUpdat e()
Me.Pass = Me.Mark >= 24
End Sub

Didn't get anything when I tried it out on the form, but when I closed
the form I got a runtime error '2113' "The value you have entered
isn't valid for this field" ....I clicked the Debug button. This
brought me back to the VBA code and the line:

Me.Pass = Me.Mark >= 24

was highlighted in yellow, with a yellow arrow to the left.

This has thrown me altogether as I couldn't find out how to actually
debug.

In the database I'm creating, I have made a relationship between the
"Student Details" table and the "Exam details" table so that I have a
single form with some fields from each table.

The Student Details Section Is at the top of the form, i.e ID, Name &
Location, and the Exam details are sort of embedded into this form in
the bottom half.

This means that a subform also exists for Exam details. I thought this
might have some baring on the result and placed the code in both the
form and the subform but the result is exactly the same.
Nov 12 '05 #11
Four things, Terry

1) At the top of the code window you should have the 2 lines
Option Compare Database
Option Explicit

Then there will be a faint line line

2) After you have keyed in the VBA Code are you going to Menu bar at the
top and selecting
Debug -> Compile XXXXXXX(Your project name)
This checks the syntax of your code, but not it's logic

3) On the properties box, if you select the All option, the Name of the
controls in question must be
"MARK" and "Pass" without the inverted commas

4) On the properties box, if you select the Event option
does the Form On Current have [Event Procedure] beside it
and
does the Text Box named MARK have [Event Procedure] beside it

Phil

"Terry" <tc*****@mersey mail.com> wrote in message
news:38******** *************** ***@posting.goo gle.com...
Ji****@NOTdatac entricsolutions .com (Jim Allensworth) wrote in message news:<3f******* ******@netnews. comcast.net>...
On Sun, 23 Nov 2003 15:26 +0000 (GMT Standard Time), ru***@127.0.0.1
(Peter Russell) wrote:
Phil Stanton previously wrote:

> Private Sub MARK_AfterUpdat e()
>
If me.MARK >= XXXXX Then 'what?
me.Pass = True
> Else
> me.Pass = False
> End If
>
> End Sub

Or simply...
Private Sub MARK_AfterUpdat e()
Me.PASS = Me.MARK >= 24
End Sub

- Jim


Jim, Tried this one first:

Private Sub Mark_AfterUpdat e()
If Me.MARK >= 24 Then
Me.Pass = True
Else
Me.Pass = False
End If
End Sub

This had no effect and showed no errors. So I tried the second one as

follows:
Private Sub Mark_AfterUpdat e()
Me.Pass = Me.Mark >= 24
End Sub

Didn't get anything when I tried it out on the form, but when I closed
the form I got a runtime error '2113' "The value you have entered
isn't valid for this field" ....I clicked the Debug button. This
brought me back to the VBA code and the line:

Me.Pass = Me.Mark >= 24

was highlighted in yellow, with a yellow arrow to the left.

This has thrown me altogether as I couldn't find out how to actually
debug.

In the database I'm creating, I have made a relationship between the
"Student Details" table and the "Exam details" table so that I have a
single form with some fields from each table.

The Student Details Section Is at the top of the form, i.e ID, Name &
Location, and the Exam details are sort of embedded into this form in
the bottom half.

This means that a subform also exists for Exam details. I thought this
might have some baring on the result and placed the code in both the
form and the subform but the result is exactly the same.

Nov 12 '05 #12
tc*****@merseym ail.com (Terry) wrote in message news:<38******* *************** ****@posting.go ogle.com>...
Ji****@NOTdatac entricsolutions .com (Jim Allensworth) wrote in message news:<3f******* ******@netnews. comcast.net>...
On Sun, 23 Nov 2003 15:26 +0000 (GMT Standard Time), ru***@127.0.0.1
(Peter Russell) wrote:
Phil Stanton previously wrote:

> Private Sub MARK_AfterUpdat e()
>
If me.MARK >= XXXXX Then 'what?
me.Pass = True
> Else
> me.Pass = False
> End If
>
> End Sub

Or simply...
Private Sub MARK_AfterUpdat e()
Me.PASS = Me.MARK >= 24
End Sub

- Jim


Jim, Tried this one first:

Private Sub Mark_AfterUpdat e()
If Me.MARK >= 24 Then
Me.Pass = True
Else
Me.Pass = False
End If
End Sub

This had no effect and showed no errors. So I tried the second one as follows:

Private Sub Mark_AfterUpdat e()
Me.Pass = Me.Mark >= 24
End Sub

Didn't get anything when I tried it out on the form, but when I closed
the form I got a runtime error '2113' "The value you have entered
isn't valid for this field" ....I clicked the Debug button. This
brought me back to the VBA code and the line:

Me.Pass = Me.Mark >= 24

was highlighted in yellow, with a yellow arrow to the left.

This has thrown me altogether as I couldn't find out how to actually
debug.

In the database I'm creating, I have made a relationship between the
"Student Details" table and the "Exam details" table so that I have a
single form with some fields from each table.

The Student Details Section Is at the top of the form, i.e ID, Name &
Location, and the Exam details are sort of embedded into this form in
the bottom half.

This means that a subform also exists for Exam details. I thought this
might have some baring on the result and placed the code in both the
form and the subform but the result is exactly the same.


UPDATE!

I discovered that the Check Box actually had the wrong name. When I
looked at the Check Box Name in it's properties I found it had been
given the default name of Check20, so I changed it and the code works,
up to a point, I'll get to that later.

I also need to do the same with another Check Box, Resit, from the
same control so I put in extra code as follows:

Private Sub Mark_AfterUpdat e()

If Me.Mark >= 24 Then
Me.Pass = True
Me.Resit = False
Else
Me.Pass = False
Me.Resit = True
End If

End Sub

And this works also, up to a point. The point being that I need to set
the two Check Boxes Pass & Resit if I have no data in the Mark Text
Box, which is by the way set to Number Double Datatype. This doesn't
happen if I delete the data from the Mark Box, the Check Boxes remain
ticked.
I tried creating a new sub as follows:

Private Sub Mark_AfterUpdat e()

If Me.Mark >= IsNull Then
Me.Pass = False
Me.Resit = False
End If

End Sub

But this created a compile error. Is there any way I can do this?

Terry
Nov 12 '05 #13
Private Sub Mark_AfterUpdat e()

If IsNull(Me.Mark) Then
Me.Pass = False
Me.Resit = False
Else
Me.Pass = (Me.Mark >= 24)
Me.Resit = Not Me.Pass
End If

End Sub
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(No private e-mails, please)

"Terry" <tc*****@mersey mail.com> wrote in message
news:38******** *************** ***@posting.goo gle.com...
tc*****@merseym ail.com (Terry) wrote in message

news:<38******* *************** ****@posting.go ogle.com>...
Ji****@NOTdatac entricsolutions .com (Jim Allensworth) wrote in message news:<3f******* ******@netnews. comcast.net>...
On Sun, 23 Nov 2003 15:26 +0000 (GMT Standard Time), ru***@127.0.0.1
(Peter Russell) wrote:

>Phil Stanton previously wrote:
>
>> Private Sub MARK_AfterUpdat e()
>>
> If me.MARK >= XXXXX Then 'what?
> me.Pass = True
>> Else
>> me.Pass = False
>> End If
>>
>> End Sub
>
Or simply...
Private Sub MARK_AfterUpdat e()
Me.PASS = Me.MARK >= 24
End Sub

- Jim


Jim, Tried this one first:

Private Sub Mark_AfterUpdat e()
If Me.MARK >= 24 Then
Me.Pass = True
Else
Me.Pass = False
End If
End Sub

This had no effect and showed no errors. So I tried the second one as follows:
Private Sub Mark_AfterUpdat e()
Me.Pass = Me.Mark >= 24
End Sub

Didn't get anything when I tried it out on the form, but when I closed
the form I got a runtime error '2113' "The value you have entered
isn't valid for this field" ....I clicked the Debug button. This
brought me back to the VBA code and the line:

Me.Pass = Me.Mark >= 24

was highlighted in yellow, with a yellow arrow to the left.

This has thrown me altogether as I couldn't find out how to actually
debug.

In the database I'm creating, I have made a relationship between the
"Student Details" table and the "Exam details" table so that I have a
single form with some fields from each table.

The Student Details Section Is at the top of the form, i.e ID, Name &
Location, and the Exam details are sort of embedded into this form in
the bottom half.

This means that a subform also exists for Exam details. I thought this
might have some baring on the result and placed the code in both the
form and the subform but the result is exactly the same.


UPDATE!

I discovered that the Check Box actually had the wrong name. When I
looked at the Check Box Name in it's properties I found it had been
given the default name of Check20, so I changed it and the code works,
up to a point, I'll get to that later.

I also need to do the same with another Check Box, Resit, from the
same control so I put in extra code as follows:

Private Sub Mark_AfterUpdat e()

If Me.Mark >= 24 Then
Me.Pass = True
Me.Resit = False
Else
Me.Pass = False
Me.Resit = True
End If

End Sub

And this works also, up to a point. The point being that I need to set
the two Check Boxes Pass & Resit if I have no data in the Mark Text
Box, which is by the way set to Number Double Datatype. This doesn't
happen if I delete the data from the Mark Box, the Check Boxes remain
ticked.
I tried creating a new sub as follows:

Private Sub Mark_AfterUpdat e()

If Me.Mark >= IsNull Then
Me.Pass = False
Me.Resit = False
End If

End Sub

But this created a compile error. Is there any way I can do this?

Terry

Nov 12 '05 #14
Thanks Doug, Jim & Phil,

I have used Doug's code, very impressive, and now have no problems:

Private Sub Mark_AfterUpdat e()

If IsNull(Me.Mark) Then
Me.Pass = False
Me.Resit = False
Else
Me.Pass = (Me.Mark >= 24)
Me.Resit = Not Me.Pass
End If

End Sub


In conclusion, my problem began because I didn't verify the name of my
Check Box as Pass, which the debugger didn't pick up on, hence no
error messages. Once this was corrected everything was OK.
Thanks for all your help.
Nov 12 '05 #15
Thanks Doug, very impressive, this works like a dream. Thanks also To Jim and Phil.

"Douglas J. Steele" <NOSPAM_djsteel e@NOSPAM_canada .com> wrote in message news:<Pr******* **********@twis ter01.bloor.is. net.cable.roger s.com>...
Private Sub Mark_AfterUpdat e()

If IsNull(Me.Mark) Then
Me.Pass = False
Me.Resit = False
Else
Me.Pass = (Me.Mark >= 24)
Me.Resit = Not Me.Pass
End If

End Sub

Nov 12 '05 #16
Terry, regarding control names (and other objects), consider using a
naming convention such as Leszynski/Reddick. It is easy to simply
preface your control with a tag indicating what type they are. IMO, it
will make your code easier to maintain. For more ...

http://www.mvps.org/access/general/gen0012.htm

Good luck,
- Jim

On 24 Nov 2003 04:01:25 -0800, tc*****@merseym ail.com (Terry) wrote:
Thanks Doug, Jim & Phil,

I have used Doug's code, very impressive, and now have no problems:

Private Sub Mark_AfterUpdat e()

If IsNull(Me.Mark) Then
Me.Pass = False
Me.Resit = False
Else
Me.Pass = (Me.Mark >= 24)
Me.Resit = Not Me.Pass
End If

End Sub


In conclusion, my problem began because I didn't verify the name of my
Check Box as Pass, which the debugger didn't pick up on, hence no
error messages. Once this was corrected everything was OK.
Thanks for all your help.


Nov 12 '05 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
24039
by: Random Person | last post by:
Does anyone know how to use VBA to relink tables between two MS Access databases? We have two databases, one with VBA code and the other with data tables. The tables are referenced by linked tables in the database where the code resides. If we move the database with the data tables to a new directory, the links are no longer valid. I tried to update the links by changing the Connect property and refreshing: Set td = db.TableDefs(0)...
6
4764
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much appreciated. Thanks in advance
7
4202
by: Ottar | last post by:
I've made a program sorting incomming mail in public folder. The function runs every minute by using the form.timer event. In Access XP it runs for weeks, no problem. Access 2003 runs the same code for 6 hours and stops. I've found the problem to be the Set MySession = CreateObject("MAPI.Session")
49
14364
by: Yannick Turgeon | last post by:
Hello, We are in the process of examining our current main application. We have to do some major changes and, in the process, are questionning/validating the use of MS Access as front-end. The application is relatively big: around 200 tables, 200 forms and sub-forms, 150 queries and 150 repports, 5GB of data (SQL Server 2000), 40 users. I'm wondering what are the disadvantages of using Access as front-end? Other that it's not...
42
11561
by: lauren quantrell | last post by:
So many postings on not to use the treeview control, but nothing recently. Is it safe to swim there yet with Access 2000-Access 2003?
5
2693
by: Lyle Fairfield | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/callnetfrcom.asp The Joy of Interoperability Sometimes a revolution in programming forces you to abandon all that's come before. To take an extreme example, suppose you have been writing Visual Basic applications for years now. If you're like many developers, you will have built up a substantial inventory of code in that time. And if you've been following...
7
2636
by: thebarefootnation | last post by:
Hi, I have created an access db that I would like to secure. The database will exist on a shared drive and be used at a number of different locations hence the reason to secure the database. The users of the database also use other databases therefore I want to secure this database without using the wizard so it does not effect their other databases.
10
409
by: Les Desser | last post by:
In article <fcebdacd-2bd8-4d07-93a8-8b69d3452f3e@s50g2000hsb.googlegroups.com>, The Frog <Mr.Frog.to.you@googlemail.comMon, 14 Apr 2008 00:45:10 writes Thank you for that. It was very clear and I actually understand it!
16
11864
by: John | last post by:
I am looking for VBA code that will work with Access 2003 to enable dragging and dropping a file/folder name from Windows XP Explorer into an Access form's text box. This is a common functionality that most Windows programs have, so I'm suprised it's not easier to implement in Access/VBA. Through Google, I found two VB6 examples and one VBA example on the Access Web written by Dev Ashish. The VB6 examples used loops to keep checking...
7
2025
by: JDOMPer | last post by:
Don’t misunderstand me – I use AJAX, but I think there is a far simpler, elegant alternative that just uses Javascript, the DOM and Php ( hence - JDOMP) for data transfers, and is cross-browser without the need for work arounds. JDOMP works in recent versions of Explorer, Mozilla, Safari and Opera. Please note I will not deal with security issues which are always an issue whenever there is access to a database. You can simply change text on...
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9577
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10315
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10075
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9140
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5519
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4295
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.