473,503 Members | 722 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

If statements for Yes/No fields

11 New Member
Hi.
I'm relatively new to using Access, and I have a specific thing I can't get to work:

I have a table called tbl_visits and within that table a field for "signed_out", which is a yes/no (boolean) field. Basically, from within a form, when a button is pressed, the database needs to return whether the "signed_out" field is yes or no and take appropriate action. Current code:

Expand|Select|Wrap|Line Numbers
  1. If DLookup("signed_out", "[tbl_visits]", "") = True Then
  2.  
  3. (action goes here)
  4.  
  5. Else
  6.  
  7. (action goes here)
  8.  
  9. End If
However, this doesn't work and i have tried many combinations of the DLookup command to no avail. Please shed some light on this. Thanks.
Dec 19 '07 #1
14 7587
Nathan H
104 New Member
Hi.
I'm relatively new to using Access, and I have a specific thing I can't get to work:

I have a table called tbl_visits and within that table a field for "signed_out", which is a yes/no (boolean) field. Basically, from within a form, when a button is pressed, the database needs to return whether the "signed_out" field is yes or no and take appropriate action. Current code:


Expand|Select|Wrap|Line Numbers
  1. If DLookup("signed_out", "[tbl_visits]", "") = True Then
  2.  
  3. (action goes here)
  4.  
  5. Else
  6.  
  7. (action goes here)
  8.  
  9. End If
However, this doesn't work and i have tried many combinations of the DLookup command to no avail. Please shed some light on this. Thanks.

If the table is the record source of the form:
From the Form:
[Code = vb]
If [Forms]![frmForm]![signed_out].Value = True Then

Else

End If
[/code]
Dec 19 '07 #2
Risk80
11 New Member
Thanks for your quick reply.

It needs to link to a table not a form, so i changed the code to:

Expand|Select|Wrap|Line Numbers
  1. If [Tables]![tbl_visits]![signed_out].Value = True Then
  2.  
  3. (do stuff)
  4.  
  5. End If
which is basically what i need to do, however this doesn't work. The form is referring to a table, not another form. Please advise.
Dec 19 '07 #3
Nathan H
104 New Member
Thanks for your quick reply.

It needs to link to a table not a form, so i changed the code to:

Expand|Select|Wrap|Line Numbers
  1. If [Tables]![tbl_visits]![signed_out].Value = True Then
  2.  
  3. (do stuff)
  4.  
  5. End If
which is basically what i need to do, however this doesn't work. The form is referring to a table, not another form. Please advise.

you stated that you wanted to call this from a form. What is the record source of that form?
Dec 19 '07 #4
Dan2kx
365 Contributor
I think it is because you need a where clause to limit the returned values,
so have "tbl.id = [forms][frmform]![form]![control]"
Dec 19 '07 #5
Risk80
11 New Member
you stated that you wanted to call this from a form. What is the record source of that form?
The record source of the form is the visits table. Basically, the signed_out is not shown on the form, thus it only exists in the table. This is because it doesn't need to be changed manually and can be handled automatically if I can get this to work. Basically, I type something into the form, and whether or not the signed_out (yes/no object) is set to yes or no depends on whether a certain message box is shown.

The only part I can't cope with is accessing the table from within a form. Sorry for not being precise in my explanation of the problem previously.
Dec 19 '07 #6
Nathan H
104 New Member
The record source of the form is the visits table. Basically, the signed_out is not shown on the form, thus it only exists in the table. This is because it doesn't need to be changed manually and can be handled automatically if I can get this to work. Basically, I type something into the form, and whether or not the signed_out (yes/no object) is set to yes or no depends on whether a certain message box is shown.

The only part I can't cope with is accessing the table from within a form. Sorry for not being precise in my explanation of the problem previously.

If you put the signed_out field on the form, mark the "Visible" property to False (so that you can not see it), and then run the code I put in above, then it should work...
Dec 19 '07 #7
jaxjagfan
254 Recognized Expert Contributor
The signed_out value cannot be read from the table until the record is saved or refreshed.

I normally assign this value to a variable as well as the table. That way I don't have to refresh my records and can use the variable for multiple functions.

In the top of your form:

DIM iSignout

Private Sub cmdSign_Out_Click()

doSignout

End Sub

Function doSignout ()

iSignout = -1 '(Yes value)
If iSignout = -1 then
doStuff
Else
dontdoStuff
End if

End Function
Dec 19 '07 #8
Nathan H
104 New Member
The signed_out value cannot be read from the table until the record is saved or refreshed.

I normally assign this value to a variable as well as the table. That way I don't have to refresh my records and can use the variable for multiple functions.

In the top of your form:

DIM iSignout

Private Sub cmdSign_Out_Click()

doSignout

End Sub

Function doSignout ()

iSignout = -1 '(Yes value)
If iSignout = -1 then
doStuff
Else
dontdoStuff
End if

End Function

Alright...going back to your original code try this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2.       If DLookup("[signed_out]", "tbl_visits", "[Account] =" & Forms!Form1!Account) = True Then
  3.  
  4.       MsgBox "signed_out True"
  5.  
  6.       Else
  7.  
  8.       MsgBox "signed_out False"
  9.       End If
  10.  
  11. End Sub
  12.  
The field "Account" should be a field that is both on your form and in the table.
Dec 19 '07 #9
Risk80
11 New Member
Still can't get it to work. I just realised that the form doesn't have a record source, and i was unable to get the code above to work. This is turning into a headache.
Edit, posted this before i saw the reply directly above, however I can't get it to work because I dont know what to replace the word "account" with. I haven't had much experience with this sort of stuff however I feel that the Dlookup method is the method I'm looking for.
Dec 19 '07 #10
Nathan H
104 New Member
Still can't get it to work. I just realised that the form doesn't have a record source, and i was unable to get the code above to work. This is turning into a headache.
Edit, posted this before i saw the reply directly above, however I can't get it to work because I dont know what to replace the word "account" with. I haven't had much experience with this sort of stuff however I feel that the Dlookup method is the method I'm looking for.
Can you post what fields you have in your table and a short description. Also tell me which of these fields you plan to show on your form.
Dec 19 '07 #11
Risk80
11 New Member
Can you post what fields you have in your table and a short description. Also tell me which of these fields you plan to show on your form.
The fields in the table are:

Visit ID ( Auto number)
Visitor ID ( Number)
Date of visit ( Date/time)
Time of sign in (Date/time)
Time of sign out ( Date/time)
Staff name ( Text)
Reason for visit ( Memo)
Signed out ( Yes/No)

I am only dealing with the sign out part of the system at the moment.

So basically a visitor gets a unique number (visit ID) and they enter this into the system upon leaving. The form therefore has a visit ID text box (where visitor enters their Visit ID). Below this I have Time (just takes current time). And below that, there is a button saying "Sign out". Basically I have done the difficult stuff by creating a query to update the database based on what is in the Visit ID field, and basically everything works fine. When the query is ran, the system Time is entered in time of sign out field and "signed out" is set to yes. This all works fine.

However, the problem is that the query will only need to run if the user hasn't yet signed out, thus the database needs to read the "Signed out" field. The query already doesn't update the field if it already contains data, so this improvement is more to avoid confusion for the user than for core workings of the system.

All i need to do is for the system to be able to read the yes/no field and show a message explaining what the database is already doing, eg "Sign out complete", or "You entered an invalid visit ID or have already signed out, database not updated".

Sorry about the excessive length - just giving the full picture.
Dec 19 '07 #12
Nathan H
104 New Member
The fields in the table are:

Visit ID ( Auto number)
Visitor ID ( Number)
Date of visit ( Date/time)
Time of sign in (Date/time)
Time of sign out ( Date/time)
Staff name ( Text)
Reason for visit ( Memo)
Signed out ( Yes/No)

I am only dealing with the sign out part of the system at the moment.

So basically a visitor gets a unique number (visit ID) and they enter this into the system upon leaving. The form therefore has a visit ID text box (where visitor enters their Visit ID). Below this I have Time (just takes current time). And below that, there is a button saying "Sign out". Basically I have done the difficult stuff by creating a query to update the database based on what is in the Visit ID field, and basically everything works fine. When the query is ran, the system Time is entered in time of sign out field and "signed out" is set to yes. This all works fine.

However, the problem is that the query will only need to run if the user hasn't yet signed out, thus the database needs to read the "Signed out" field. The query already doesn't update the field if it already contains data, so this improvement is more to avoid confusion for the user than for core workings of the system.

All i need to do is for the system to be able to read the yes/no field and show a message explaining what the database is already doing, eg "Sign out complete", or "You entered an invalid visit ID or have already signed out, database not updated".

Sorry about the excessive length - just giving the full picture.
[Code =vb]
Private Sub Command2_Click()

If DLookup("[signed_out]", "tbl_visits", "[Visit ID] =" & Forms![YOUR FORM NAME]![Visit ID]) = True Then

MsgBox "signed_out True"

Else

MsgBox "signed_out False"
End If

End Sub
[/code]
Dec 19 '07 #13
Risk80
11 New Member
[Code =vb]
Private Sub Command2_Click()

If DLookup("[signed_out]", "tbl_visits", "[Visit ID] =" & Forms![YOUR FORM NAME]![Visit ID]) = True Then

MsgBox "signed_out True"

Else

MsgBox "signed_out False"
End If

End Sub
[/code]
Works absolutely flawlessly! Thankyou very much for your time. This has helped me a lot. :)
Dec 19 '07 #14
Nathan H
104 New Member
Works absolutely flawlessly! Thankyou very much for your time. This has helped me a lot. :)

Great news. Good luck
Dec 19 '07 #15

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

Similar topics

9
2616
by: Jaime Wyant | last post by:
I know I've seen this somewhere, but can't seem to google it. Is there a way to use an alternate statement separator, other than the default ';'? jw
2
2225
by: misschristalee | last post by:
I'm having a brain blockage day.... Scenario: Search Form with 6 text boxes Query has same six fields Each has this IIF: IIf(IsNull(!!),"",!!) with each dictating the correct text box of...
1
2196
by: jan | last post by:
Hello, I am new to this list and would appreciate some help with Access 2000 and Access 2003. I need to export our access database table statements by access database to place into our database...
16
3271
by: klowe | last post by:
Hi, I'm an Access newbie and need to update an Access database from a web application. I'll need to add new records and also update existing ones. What I was thinking of doing is have my web app...
2
3111
by: Annie D via AccessMonster.com | last post by:
Hi, Is it possible to use multiple statements in SQL?? (I’ve never used it before) : I have one query that i'm working with, The statements I want to use are as below, they all work...
6
1884
by: Jerry Evenden | last post by:
Just an old C programmer trying to learn a new trick with C++ so excuse the dumb question: The use of the "map" list seems quite useful to me for an application updating an existing C system. ...
5
1441
by: ZaphodBBB | last post by:
I have a form that is used just to review previously saved records.(1 record at a time). It also allows just a couple of fields to be updatable (in a given record)and resaved. I load all the...
1
2557
by: bimeldip | last post by:
Hi, I have managed to create codes to display data from the database in a html page.I have gone on to create a page to allow users to manipulate the table via a html page. For instance users will be...
0
2060
by: bimeldip | last post by:
Hi, I have managed to create codes to display data from the database in a html page.I have gone on to create a page to allow users to manipulate the table via a html page. For instance users will be...
1
1315
by: jock1up | last post by:
Been working on some programming exercises in my spare time and don't fully understand this one related to ADO....Appreciate any help on this. The name of the ADO data control is adoNum-----Was...
0
7203
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
7089
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...
0
7282
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
5581
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,...
1
5017
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4678
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3157
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1515
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 ...
1
738
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.