473,320 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

If Statement question

158 100+
I have a very easy one for you guys:

I have a checkbox that is called [ProjectDetailActive]
it's default value is "true"

I would like to insert a code that would make it impossible to turn the checkbox to false if another field on the same form[ProjectDetailEndDate] = null

A side Comment:
I don't know how you guys manage to find the correct statement for these codes. Where do you guys learn this stuff? I've read articles, books, visited web sites but nowhere yet in two years have I found a place that teach how to write codes - they only give you an examples on how a code might read for a function that I would never use in a million year and never close to what I need. is there like a secret Harry Potter school where they do teach you how to write codes?

I've asked this question hundreds of times all over the internet and nobody seem to know. All trial and error I hear all the time- is that true? there is nowhere to learn how to write codes? I'm doomed :o)
Jan 19 '11 #1

✓ answered by pod

For starters, let's put in the right names for the fields and correct the desired value for the checkbox, (I had it reversed)
Expand|Select|Wrap|Line Numbers
  1. Private Sub PDActive_AfterUpdate() 
  2.     Dim val As Variant 
  3.     val = Trim(Me.PDEndDate.Value) 
  4.     If IsNull(val) Or val = "" Or Len(val) = 0 Or Not IsDate(val) Then 
  5.         Me.PDActive = True
  6.     End If 
  7. End Sub 

13 1321
patjones
931 Expert 512MB
Hi jaad,

I would suggest using the After Update event for ProjectDetailEndDate in conjunction with the "Enabled" property for ProjectDetailActive. In particular, you can perform an If test inside the After Update event and set the checkbox Enabled property to true or false depending on what the result of the test is.

In terms of learning how to code...you learn by teaching yourself general principles, and then applying those principles to your particular problem, often incorporating trial and error. If you go to sources of information looking for the exact code to solve your problem, your search will almost always be futile.

Pat
Jan 20 '11 #2
jaad
158 100+
This is the code that I've picked up from a You tube video and adapted it to my need.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.     If ([PDEndDate] = Null) And ([PDActive] = False) Then
  3.     MsgBox ("You cannot deactivate a record without first entering an End Date to the project")
  4.     Cancel = True
  5.  
  6. End If
  7. End Sub
  8.  
Why would this not work?

I've tried to place it into the [PDActive] beforeUpdate and AfterUPdate and OnClick and none work.
Jan 20 '11 #3
patjones
931 Expert 512MB
What happens when you try to use it? Does it produce an error? Is there some sort of strange behavior? You need to explain more clearly what's happening.

Pat
Jan 20 '11 #4
jaad
158 100+
Nothing happens. It's like it wasn't even there.
Jan 20 '11 #5
patjones
931 Expert 512MB
I tested this out and it seems to work fine:

Expand|Select|Wrap|Line Numbers
  1. Private Sub PDActive_BeforeUpdate(Cancel As Integer)
  2.  
  3. If ([PDEndDate] = Null) And ([PDActive] = True) Then
  4.     MsgBox ("You cannot deactivate a record without first entering an end date for the project.")
  5.     Cancel = True
  6. End If
  7.  
  8. End Sub
  9.  

Pat
Jan 20 '11 #6
jaad
158 100+
I just copy and paste the code into the before update of PDActive and nothing happens. again its like nothing was there.
Jan 20 '11 #7
patjones
931 Expert 512MB
Are the controls actually named PDEndDate and PDActive? In your original post you referred to them as ProjectDetailEndDate and ProjectDetailActive respectively.

Pat
Jan 20 '11 #8
jaad
158 100+
yes they are named PDActive and PDEndDate I renamed them in the table in order to make it easier to write and they all have the same name throughout with queries,forms and report and everything works fine.
Jan 20 '11 #9
pod
298 100+
The Null value can be very time consuming for beginners, ... and it still plays tricks on me :) but I learn a lot from errors in the code, so will you. Patience and time are required parameters for developers/programmers/coders.

zepphead80 suggestion is best

Try something like this:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Check2_AfterUpdate()
  2.     Dim val As Variant
  3.     val = Trim(Me.Text0.Value)
  4.     If IsNull(val) Or val = "" Or Len(val) = 0 Or Not IsDate(val) Then
  5.         Me.Check2 = False
  6.     End If
  7. End Sub
Jan 20 '11 #10
jaad
158 100+
Thanks for jumping-in Pod,

As you mentioned yourself "I am a beginner" and I unfortunately don't know what to do with the code that you wrote????? Where would I put that code? I don't have any control called Check2.


It's never easy to explain these thing but let me try again:

I have a form in which I can view and edit records for a Project table. This form's source is a query that filters out all records that are not active or [PDActive].

All project should have a starting date and an end date[PDEndDate] Once someone has worked with the record, added info and taken the project to completion you would then write the date at which you finished the project and then click the checkbox [PDActive] to deactivate the record so it doesn't show up in the form anymore.

The problem that I have is sometime people forget to write the end date [PDEndDate] and deactivate the project by clicking [PDActive].

What that does is I have to go back to the table and manually enter the date at which the project was close for every record that the end date wasn't entered. it also creates holes into my reports as I need that end date to show when the project was finalized and done with.
Jan 20 '11 #11
pod
298 100+
For starters, let's put in the right names for the fields and correct the desired value for the checkbox, (I had it reversed)
Expand|Select|Wrap|Line Numbers
  1. Private Sub PDActive_AfterUpdate() 
  2.     Dim val As Variant 
  3.     val = Trim(Me.PDEndDate.Value) 
  4.     If IsNull(val) Or val = "" Or Len(val) = 0 Or Not IsDate(val) Then 
  5.         Me.PDActive = True
  6.     End If 
  7. End Sub 
Jan 20 '11 #12
jaad
158 100+
IT WORKS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Thank you so much Pod... I have been trying to figure this one out for so long.

Can I put a msgbox()line before End iF that would read why people can't close the record?
Jan 20 '11 #13
pod
298 100+
bien sur! You can also set the focus on the date field put in the same message in a msgbox and the datefield (which will disapear when the user clicks in the PDEndDate text box)
Expand|Select|Wrap|Line Numbers
  1. Private Sub PDActive_AfterUpdate()
  2.     Dim val As Variant
  3.     val = Trim(Me.PDEndDate.Value)
  4.     If IsNull(val) Or val = "" Or Len(val) = 0 Or Not IsDate(val) Then
  5.         Me.PDActive = False
  6.         MsgBox "End date required"
  7.         Me.PDEndDate.Value = "End date required"
  8.         Me.PDEndDate.SetFocus
  9.     End If
  10. End Sub
  11.  
  12. Private Sub PDEndDate_Click()
  13.     If Me.PDEndDate.Value = "End date required" Then
  14.         Me.PDEndDate.Value = ""
  15.     End If
  16. End Sub
Jan 20 '11 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Smriti Dev | last post by:
Hi there, I have the following code: echo "\n <address>"; if ($entry_info and $entry_info != '') { echo "\n ".stripslashes($entry_info).".,"; } if ($entry_info and $entry_info != '' ) {...
4
by: J Buchman | last post by:
I'm trying to write a statement in VB 6 that will give me the overtime pay. It needs to compute the first 40 hours at the normal pay rate, then any hours over 40 at rate * 1.5, then add those amount...
1
by: ron | last post by:
Hi, I'm still new at Python and have been away from programming for a number of years in general. I apologized in advance if this has been discussed extensively already. Is the input()...
0
by: Troy | last post by:
I forgot to add this question to my last post. Can someone help me out? Question: Say you have a drop down list based on a SQL statement, want limited by the values in another control on the...
21
by: Andy | last post by:
Can someone tell me if the following Switch...Case construct is valid? I'm wanting to check for multiple values in the Case statement without explicitly listing each values. So for example, will...
2
by: hype | last post by:
Hi, 1) If I need to monitor a resource eg, bufferpools at the database level across all users, how can I do this ? If snapshot monitoring needs to be done wouldn't enabling the switch at the DBM...
2
by: matthew custer | last post by:
In VB I can have a switch statement with a Case 1 to 5 in C# it seems I have to have Case 1: Case 2: Case 3: Case 4: Case 5:
5
by: | last post by:
is there anything like a SQL IN statement where x in ('123','456',789').... available in an IF statment in aspnet? I've got a number of possibilities for a session variable to be set equal...
2
by: Cathleen C via DotNetMonster.com | last post by:
I'm a semi-beginner with c# and am having a problem effectively implementing a switch statement. I've created an asp.net app that runs a report depending on which item was selected from a drop...
1
by: Matt | last post by:
I am writing a DELETE statement and I want to filter the records using another SELECT statement. My SELECT statement is a GROUP BY query that grabs all social security numbers from the "Data...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.