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

Value determined by VBA coding does not show in table

Hello,
So I have a worksheet on access with my VBA code along with a form and a table on access. All three of these are connected and work off of each other. My problem is that I have a value (T-Score) that is calculated by VBA with an If Then statement but it does not show the value on the table with the rest of the data. Anyone have any idea how to connect the two?
Jan 9 '14 #1
6 1266
zmbd
5,501 Expert Mod 4TB
lburleigh:
You need to show your code.[*]> Before Posting (VBA or SQL) Code
Jan 9 '14 #2
Expand|Select|Wrap|Line Numbers
  1. Sub Boys7to12()
  2.    If [Total Score] >= 39 Then
  3.       [T-Score] = 90
  4.       ElseIf [Total Score] = 38 Then
  5.          [T-Score] = 89
  6.          ElseIf [Total Score] = 37 Then
  7.             [T-Score] = 88
  8.    End If
  9. End Sub
(in the actual coding, it continues the same until 0.
Jan 9 '14 #3
zmbd
5,501 Expert Mod 4TB
1) This is a sub not a function; therefor, it's not supposed to return a value.

2) There are neither recordsets opened nor SQL executed to update a field

3) Where are you attempting to use this code from: a form, a calculated control, a table field?

I take it that you are fairly new to database design, Access, and VBA?
Jan 9 '14 #4
1) so if I instead use a code like...
Expand|Select|Wrap|Line Numbers
  1. Public Function getAgePhrase(ByVal age As Integer) As String 
  2.     If age > 60 Then Return "Senior" 
  3.     If age > 40 Then Return "Middle-aged" 
  4.     If age > 20 Then Return "Adult" 
  5.     If age > 12 Then Return "Teen-aged" 
  6.     If age > 4 Then Return "School-aged" 
  7.     If age > 1 Then Return "Toddler" 
  8.     Return "Infant" 
  9. End Function
would that allow it to return the corresponding value?

2) I don't quite understand when to properly use SQL. Is it necessary here?

3) all of the above. the form is interactive for others to input their necessary data and then it connects to a table field where the data is simplified and displayed in an easy to read format.

I am pretty new to all of it and only know basics but I am trying to learn. Thank you so much for your help and patience.
Jan 9 '14 #5
zmbd
5,501 Expert Mod 4TB
1) So in a query or the control source for a form control:
Expand|Select|Wrap|Line Numbers
  1. Query:
  2. FieldName: getAgePhrase([AgeField])
In a control's property sheet, data tab, property [Control Source], provided the [AgeField] was in the form's record set or available in an unbound text box then:
Expand|Select|Wrap|Line Numbers
  1. =getAgePhrase([AgeField])
You would not normally use this in a table.

>>> I would also not hard code the example you've given for the age range - it's hard to maintain. Instead I would have a table with these text results and a query that returns the value based on the criteria see (2). You might have to redesign the table structure as well as often when I see things like this hardcoded there is an underlying weakness in the database design.

2) The answer is both yes and no, see (1). If you use the function in a query, via the query editor (QE), you are using SQL, just that Access has hidden it behind a pretty dialog box. You can see the SQL script by right clicking in the table area of the QE and selecting SQL-View. (Select design view to go back to the happy place (^_^) )

3)That was the impression I had of what was happening. Even though everything is related, it's not always so direct which can be confusing and frustrating (even to us old-hands)! So in your case using the vba in order for the VBA (or Macro which is a 2nd language avaiable in Access) to have an effect on a record set there must be an explict value change. This can happen in a form if the control is bound to table/query and the VBA alters the value of bound control, the VBA opens a recordset and updates the values (can even be the form's recordset), the VBA uses the execute method on an action SQL (such as INSERT or UPDATE).

4) I'm going to PM you my standard list of what I hope are helpfull links. There are some tutorials in this that I highly recommend you take a careful look at (and hopefully work thru the hands-on one). There is a sublink in the hands-on one that works thru database design (in ACC2003; however, the concepts still hold true) that you might find of great help.
Jan 9 '14 #6
Thank you so much!! You have been such a great help! I will definitely look through the links you send.
I will play around with all the information you have given me and hopefully work it out. I really appreciate all your time. :)
Jan 9 '14 #7

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

Similar topics

0
by: Jerry | last post by:
The "SHOW TABLE STATUS" command seems to return a result set, just like "SELECT * FROM SomeTable". Therefore, since the following is valid: SELECT * FROM (SELECT * FROM SomeTable) I...
1
by: Ken Elder | last post by:
I need to place the date a MySQL table was last updated into a PHP variable. SHOW TABLE STATUS provides lots of information, including update_time, for all of my tables. But how do I assign the...
14
by: inquirydog | last post by:
Hi- One frusterating thing for me with xsl is that I don't know how to make xslt throw some sort of exception when a value-of path does not exist. For instance, suppose I have the following...
0
by: 400PM | last post by:
Hi, I am using java to retrieve a resultset with "show table status" mysql command. I am having problem reading the and column. In the metadata object it is showing as VARCHAR but when I do...
6
by: Christopher Lusardi | last post by:
How can I fix this? When I do the below I get the error message: "Cannot insert explict value for identity column in table 'Employees' when IDENTITY_INSERT is set to OFF." To get this message,...
0
by: =?Utf-8?B?Y2NfY3Jhc2g=?= | last post by:
Hello all, This is probably a simple issue but since I am a newbie I am really stuck on it. I have been developing some code and I was using rowPosition to pull data from a Access Data base and...
1
by: runway27 | last post by:
hi I am using MySQL - 4.1.22 when i use the following sql query $result = mysql_query("SHOW tablename STATUS FROM databasename;"); i have also tried = $result = mysql_query("SHOW tablename...
2
by: Sudhakar | last post by:
hi I am using MySQL - 4.1.22 when i use the following sql query $result = mysql_query("SHOW tablename STATUS FROM databasename;"); i have also tried = $result = mysql_query("SHOW tablename...
0
by: runway27 | last post by:
hi my question is about "SHOW TABLE STATUS LIKE 'tablename'"; following is the code i am presently using ================================================================== $conn =...
3
by: debo sniffa | last post by:
I want to add a value from a record in Table A to a record in table B if the value is same as 2 other fields in the Table A. How could i get this done in access?? Pls help me... ;-)
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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
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
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,...

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.