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: - If DLookup("signed_out", "[tbl_visits]", "") = True Then
-
-
(action goes here)
-
-
Else
-
-
(action goes here)
-
-
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.
14 7587
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: - If DLookup("signed_out", "[tbl_visits]", "") = True Then
-
-
(action goes here)
-
-
Else
-
-
(action goes here)
-
-
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]
Thanks for your quick reply.
It needs to link to a table not a form, so i changed the code to: - If [Tables]![tbl_visits]![signed_out].Value = True Then
-
-
(do stuff)
-
-
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.
Thanks for your quick reply.
It needs to link to a table not a form, so i changed the code to: - If [Tables]![tbl_visits]![signed_out].Value = True Then
-
-
(do stuff)
-
-
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?
I think it is because you need a where clause to limit the returned values,
so have "tbl.id = [forms][frmform]![form]![control]"
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.
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...
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
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: -
Private Sub Command1_Click()
-
If DLookup("[signed_out]", "tbl_visits", "[Account] =" & Forms!Form1!Account) = True Then
-
-
MsgBox "signed_out True"
-
-
Else
-
-
MsgBox "signed_out False"
-
End If
-
-
End Sub
-
The field "Account" should be a field that is both on your form and in the table.
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.
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.
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.
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]
[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. :)
Works absolutely flawlessly! Thankyou very much for your time. This has helped me a lot. :)
Great news. Good luck
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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...
|
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...
|
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...
|
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...
| |
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.
...
|
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...
|
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...
|
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...
|
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...
|
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,...
| |
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: 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,...
|
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,...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |