473,387 Members | 1,517 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,387 software developers and data experts.

Creating skip rule in MS Access?

9
I am developing a database in MS Access. I want to create a skip rule. Following is an example of the problem:

The first question: 'Are you a student'. The next question is 'which school do you go to?'. and then the next one is 'how old are you?'.

In the above context if someone answers 'No' to the first question then the second question does not apply to that person so we can jump to the third question. I want to know how to create this skip rule in MS Access so after entering 'no' to the first question if one hit 'tab' it will take him/ her to the third question while skip the second one.

Any help is appreciated.

Thanks
Aug 8 '06 #1
10 5307
comteck
179 100+
You simply use an IF..THEN statement, with each question as part of a SUB. For example:

Private Sub Command5_Click()
If Question1 = A Then
Call SUB1
Else
Call SUB2
End If
End Sub

Private Sub SUB1()
'(Enter Code Here for Question 2)
End Sub

Private Sub SUB2()
'(Enter Code Here for Question 3)
End Sub

Hope this helps.
comteck
Aug 8 '06 #2
Arif
9
Thanks for your help. However I am a novice in Access. Where to write the commands? Do I have to use Macro?

Thanks

Aha
Aug 8 '06 #3
comteck
179 100+
No.. Code is not written in a macro. In this case, the code is written using "Code Builder".

Create a new Command Button (turn off the wizard - or cancel when it appears). Still in design mode, right click on the button, and select "Build Event". Then choose "Code Builder". This will automatically create an OnClick Event Procedure for that button. Visual Basic will open, and the following code will appear (or something similar):

Private Sub Command5_Click()

End Sub

You then put the following code in between these 2 lines:

If Question1 = A Then
Call SUB1
Else
Call SUB2
End If

The final code will be:

Private Sub Command5_Click()
If Question1 = A Then
Call SUB1
Else
Call SUB2
End If
End Sub

Then, while still in Visual Basic, add the other subs. The final code will be:

Private Sub Command5_Click()
If Question1 = A Then
Call SUB1
Else
Call SUB2
End If
End Sub

Private Sub SUB1()
'(Enter Code Here for Question 2)
End Sub

Private Sub SUB2()
'(Enter Code Here for Question 3)
End Sub

Hope this makes sense.
comteck
Aug 9 '06 #4
MMcCarthy
14,534 Expert Mod 8TB
An easier solution would be to set the Visible property of textbox 'which school do you go to?' to No on the form. (Right click on the textbox in design view and go to properties)

Then in the Events section of the properties for the textbox 'Are you a student' click on the arrow and go to [Event Procedure] then click on the button beside this with the dots on it. The VBA code editor will open with a procedure as below:

Private Sub textboxName_AfterUpdate()

End Sub

Add the line of code

If Me.textboxName = 'Yes' then
Me.otherTextBox.Visible = True
Else
Me.otherTextBox.Visible = False
End If

Hope this helps
Aug 10 '06 #5
Arif
9
I really appreciate your help. I tried the way you suggested but unfortunately it didn't work. I think I am doing some mistakes somewhere. When you said '(Enter Code Here for Question 2), what should be the code? Should I just put the question there as it is typed in the database or I have to put some code? and if it is, then what could be the code?

It would even be helpful if there is a similar example that I can follow.

Thanks a lot.
Aug 10 '06 #6
comteck
179 100+
When I say "Enter Code for Question 2", that means that the code for question 2 would have to be inserted there.

In order to give exact details of what the code would be, I would have to know exactly what the questions are, as well as the name of all the textboxes, etc that are involved.

If you want to provide all the details.. maybe include tables as well with field names.

comteck
Aug 10 '06 #7
Arif
9
Thanks.

I am furnishing a section from my database. You can see the skip instructions. I want to build these skip rules in the database.

Following are the questions that are in the database.

1.a. Did you cultivate any farmland last season? Yes...........1
No.............2 If no skip to Q. 2

1.b. Did you cultivate rice in last season? Yes...........1
No............2

Area rice cultivated _____________ (sq meter)
Quantity harvested ______________ (kilograms)

1.b. Did you cultivate maize in last season? Yes...........1
No............2

Area maize cultivated _____________ (sq meter)
Quantity harvested ______________ (kilograms)

2.a Did you have a home garden last season? Yes...........1
No.............2
If no skip to Q. 3.a.1

2.b.1 Did you buy seeds from market? Yes...........1
No.............2
2.b.2 Did you get seeds from demo plot? Yes...........1
No.............2
2.b.3 Did you get seed from local nursery? Yes...........1
No.............2
3.a.1 Did you do vermi composting last year? Yes...........1
No.............2

Thanks
Aug 10 '06 #8
Arif
9
Dear mmccarthy

Thanks for your help. Finally I was able to make it work. Thanks. I am wondering whether there is a way to fade the questions that I want to skip instead of make them invisible?
Aug 11 '06 #9
MMcCarthy
14,534 Expert Mod 8TB
Instead of using the .Visible command you could use the .Enabled command.

Set it to True when you want the user to be able to access it and to False when you want it greyed out and unavailable to the user.

Private Sub textboxName_AfterUpdate()

If Me.textboxName = 'Yes' then
Me.otherTextBox.Enabled = True
Else
Me.otherTextBox.Enabled = False
End If

End Sub
Aug 12 '06 #10
Arif
9
Thanks a lot. This was helpful.
Aug 14 '06 #11

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

Similar topics

13
by: jenny | last post by:
Hi, I am trying to find a VB way that would create a folder on all existing drives - the folder name would be the same on each drive. ie c:\backup, d:\backup, etc. But the folders would only be...
5
by: Barbara Lindsey | last post by:
Thank you for your help on the trigger question. The RULE worked for most of the cases I had for this, but I have one that is giving me trouble. Here are my table definitions: CREATE SEQUENCE...
59
by: AK | last post by:
I tried to google "skip scan DB2" but came up with nothing. Does DB2 have the feature under a different name?
5
by: alanknipmeyer | last post by:
Dear Sirs, Having previously used other SQL implementations I have grown used to having an audit trail to find when problems occured, the problem I am increasingly finding with Access is that...
24
by: Robin Cole | last post by:
I'd like a code review if anyone has the time. The code implements a basic skip list library for generic use. I use the following header for debug macros: /* public.h - Public declarations and...
6
by: Jerry Spence1 | last post by:
Why doesn't the following work in my ASP program? I have imported ADOX I am trying to create a temporary database on the user's PC. The example is taken from Microsoft. Dim cat As Catalog =...
2
by: asad | last post by:
hello, how ru all pls tell me how can i create DAL and how can i use it in my ASP.NET pages thanks
3
by: Alex.Sh | last post by:
How can i do something like this: i have a form with A percentage : ______ B percentage: ______ C percentage: ______ I want that the sum of these 3 fields *will never* be more than 100...
7
by: mlthomas007 | last post by:
Hi, A client asked for a code book (all fields, descriptions, tables, etc.) from our Access database. Has anyone had to do this? It seems to me there must be a way to extract all this...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.