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

Reference a Field's Value in a Table

132 100+
How would I reference the value of a field in a table?? I have a table named ACTIONS and a field in that table named ACTION TYPE. Would this work??

if [Action].[Action Type].Value = " Received By Inventory" Then
MsgBox ("What a LOVELY day!")

End If
Mar 10 '08 #1
6 21596
Stewart Ross
2,545 Expert Mod 2GB
How would I reference the value of a field in a table?? I have a table named ACTIONS and a field in that table named ACTION TYPE. Would this work??

if [Action].[Action Type].Value = " Received By Inventory" Then
MsgBox ("What a LOVELY day!")

End If
Hi Proaccesspro. No, what you propose would not work. You have not actually opened the table, nor selected any records, so you can't access any field values.

You could use the DoCmd.OpenRecordset method to open the Action table then process the records within a loop. There are many posts in this forum which show examples of doing exactly that, as you will find if you search accordingly.

-Stewart
Mar 10 '08 #2
Proaccesspro
132 100+
Hi Proaccesspro. No, what you propose would not work. You have not actually opened the table, nor selected any records, so you can't access any field values.

You could use the DoCmd.OpenRecordset method to open the Action table then process the records within a loop. There are many posts in this forum which show examples of doing exactly that, as you will find if you search accordingly.

-Stewart
Stewart,

I jumped the gun...I have a form that has a drop down box of values. The values of that drop down box are captured in the field ACTION TYPE in the table ACTIONS. What I am trying to do is set the value of the field EMHS received to YES if the value selected = received by emhs. Would I still need to do it the way you describe above? Also, I am checking for this with the AFTER UPDATE event.
Mar 10 '08 #3
Stewart Ross
2,545 Expert Mod 2GB
...I have a form that has a drop down box of values. The values of that drop down box are captured in the field ACTION TYPE in the table ACTIONS. What I am trying to do is set the value of the field EMHS received to YES if the value selected = received by emhs. Would I still need to do it the way you describe above? Also, I am checking for this with the AFTER UPDATE event.
Hi Proaccesspro. I think I begin to understand what you need to do, though I'm not certain. If the [ACTION TYPE] value you want to test is included in your combo box list you can access that value from the combo box directly without opening another recordset by referring to the Column property of the combo box.

If the [ACTION TYPE] value is, say, the third column in your combo you could refer to it from within the after update event code like this:

Expand|Select|Wrap|Line Numbers
  1. If Me![name of your combo].Column(2) = somevalue then
  2.     ...
Columns are numbered from 0, with the 0 column the first one, column 1 the second, and so on. A column does not have to be visible - it can have a width of zero and still be returned using the Column property. Including additional fields in a drop-down which are not visible to the user but are accessible using the Column property is a really useful way to access subsidiary information from a reference table.

-Stewart
Mar 11 '08 #4
Proaccesspro
132 100+
Hi Proaccesspro. I think I begin to understand what you need to do, though I'm not certain. If the [ACTION TYPE] value you want to test is included in your combo box list you can access that value from the combo box directly without opening another recordset by referring to the Column property of the combo box.

If the [ACTION TYPE] value is, say, the third column in your combo you could refer to it from within the after update event code like this:

Expand|Select|Wrap|Line Numbers
  1. If Me![name of your combo].Column(2) = somevalue then
  2.     ...
Columns are numbered from 0, with the 0 column the first one, column 1 the second, and so on. A column does not have to be visible - it can have a width of zero and still be returned using the Column property. Including additional fields in a drop-down which are not visible to the user but are accessible using the Column property is a really useful way to access subsidiary information from a reference table.

-Stewart
Stewart,

Exactly what I had in mind....Now the last piece of the puzzle is how to update the EMHS received field in the CASE table. This is where I get confused...Both tables (Actions and CASE) are linked with a case #.
Could it be something like I stated above:

If Me![Combo12].Column(0) = " Received By EMHS" Then
[Case].[EMHS received].vaue = 1 <-------(is 1 the value of YES?)
EndIf
Mar 11 '08 #5
Stewart Ross
2,545 Expert Mod 2GB
...Now the last piece of the puzzle is how to update the EMHS received field in the CASE table. This is where I get confused...Both tables (Actions and CASE) are linked with a case #.
Could it be something like I stated above:

If Me![Combo12].Column(0) = " Received By EMHS" Then
[Case].[EMHS received].vaue = 1 <-------(is 1 the value of YES?)
EndIf
Hi again Proaccesspro. It is not possible to refer to your CASE table directly, unless your form (or a subform within it) is already bound to it, or you have another form open which is bound to that table. Even if your form is bound to the CASE table, you would still have to go to the correct record before updating (perhaps by filtering the record).

The alternative is to use an SQL statement to update that value for you, using something like this in code:

Expand|Select|Wrap|Line Numbers
  1. Dim strSQL as String
  2. strSQL = "UPDATE [Case] SET [Case].[EMHS received] = True WHERE [Case].[case #] = " & Me![Case #]
  3. DoCmd.Setwarnings False
  4. DoCmd.RunSQL strSQL
  5. DoCmd.Setwarnings True
This assumes that (1) it is the Actions table to which your form is bound, (2) there is a current record on your form matching a current case #, (3) that the current case # is the one you want to select in your Case table, (4) that there is no other selection criteria required to select the record you want to update, and (5) that the case # is a number. If it is actually a string you would need single quotes on either side of the reference to it in the WHERE clause:
Expand|Select|Wrap|Line Numbers
  1. WHERE [Case].[case #] = '" & Me![Case #] & "'"
By the way, a Yes/No value is a boolean value. True (Yes) is stored as -1, False (No) as 0.

-Stewart

ps you don't need to use the column property when referring to the first column (column(0)) of a combo box. The two statements below would give identical results:
Expand|Select|Wrap|Line Numbers
  1. Me![combo name]
  2. Me![combo name].column(0)
Mar 11 '08 #6
Proaccesspro
132 100+
Hi again Proaccesspro. It is not possible to refer to your CASE table directly, unless your form (or a subform within it) is already bound to it, or you have another form open which is bound to that table. Even if your form is bound to the CASE table, you would still have to go to the correct record before updating (perhaps by filtering the record).

The alternative is to use an SQL statement to update that value for you, using something like this in code:

Expand|Select|Wrap|Line Numbers
  1. Dim strSQL as String
  2. strSQL = "UPDATE [Case] SET [Case].[EMHS received] = True WHERE [Case].[case #] = " & Me![Case #]
  3. DoCmd.Setwarnings False
  4. DoCmd.RunSQL strSQL
  5. DoCmd.Setwarnings True
This assumes that (1) it is the Actions table to which your form is bound, (2) there is a current record on your form matching a current case #, (3) that the current case # is the one you want to select in your Case table, (4) that there is no other selection criteria required to select the record you want to update, and (5) that the case # is a number. If it is actually a string you would need single quotes on either side of the reference to it in the WHERE clause:
Expand|Select|Wrap|Line Numbers
  1. WHERE [Case].[case #] = '" & Me![Case #] & "'"
By the way, a Yes/No value is a boolean value. True (Yes) is stored as -1, False (No) as 0.

-Stewart

ps you don't need to use the column property when referring to the first column (column(0)) of a combo box. The two statements below would give identical results:
Expand|Select|Wrap|Line Numbers
  1. Me![combo name]
  2. Me![combo name].column(0)

Stewart,
ALL IS WELL.....Thanks so much for the help!!
Mar 11 '08 #7

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

Similar topics

13
by: MLH | last post by:
I have a form with two controls: !! - combo box !! - text box A button on the form tries to run this SQL when clicked... INSERT INTO BodyMsgsSent (ToWhom, BodyText) SELECT DISTINCTROW !! AS...
1
by: Wei Wang | last post by:
Hi, Sorry for asking the dynamic command question without thoroughly reading the documentation first. Thanks a lot for your reply, Richard. ;-) Now this may be a naive SQL question: Is there...
14
by: rbowman40 | last post by:
I am trying to design a form in which a category (field in a table) is selected from a combo box, then a value for that category is entered in a form field. I want that value to be placed in the...
4
by: bdockery | last post by:
Access 2007 I have a table with three columns. Country, State, City What I want to do is have a form where the Country, and State, lookups auto-populate when the city lookup is chosen. It...
1
by: pchadha20 | last post by:
How to single numeric values from a field in a table which has multiple numeric value in a field of a table.And that table contains thousands of records. Suppose we have a table customer having...
2
by: jaad | last post by:
Ok I am seriously starting to scare myself with this one. I've only been dealing with Access 2007 since August of 2009 and being a newbee I made a lot of mistakes but learned a lot since then. My...
11
by: lee weaver | last post by:
For some reason when applyinf a filter, not changeing or adding information to my database i get a 3022 error. here is the offending code. Private Sub Updatebutton() Dim f As String ...
19
by: jaad | last post by:
how do you reference a single value field to a multi-value field? I sometime use a macro in form1 to open form 2 containing the same ID example: Open form: WorkOrder where condition: ="="...
4
by: bouldergirl | last post by:
I have 2 tables, Table 1 and Table 2 (see attached images)....Although in the example tables (attached), only a few records are shown, they both have about 1000 GRID values: Table 1 contains...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...
0
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,...
0
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...

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.