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

Home Posts Topics Members FAQ

creating formula in access

4 New Member
Hello

I am student and trying to learn access.I am having problem in making a program can any one help me?

i wanted to make 2 tables in access and then create a link.First i am telling u what these tables contain then i will proceed.

(i have also tried this in excel but failed to do so).


table 1 (contains following items)

D T
3/4 0.35
1 0.69
2.3 0.59
2/3 0.76

table 2 (contains following items)
D W
3/4 =4.85*T(D-T)
1 =4.85*T(D-T)
2/3 =4.85*T(D-T)
2.3 =4.85*T(D-T)
i want to create link in these two tables such that when i am going to enter value of D it automatically calculate the value of W (the formula of W is written in table 2) by picking up the value of T from table 1 and then doing it.

now my first problem is that i dont know how to write formula in access.Is this the way, in which i should write formula in access???? as this is the way in which we used to write formula in excel.

And my second question is that should i have to create a querry for calculating value of W.If yes then which type of querry and how.

A little bit of help will also be greatly appreciated.

Thanks.
Jul 3 '06 #1
5 12174
comteck
179 New Member
I'm not quite understanding your formulas. However, the way to do this is simple. You create a form with 2 textboxes (name them textbox1 and textbox2), and a Command button (name it btnCalculate). Right Click on the Command Button, and click "Build Event". Choose "Code Builder", and the code window will open, with the following code:

Private Sub btnCalculate_Click()

End Sub

You then put your fomula in betwwen the "Private" and "End". You also have to declare your variables (using Dim). So, it should look like this when you are done.

Private Sub btnCalculate_Click()
Dim D, W As Integer
D = Me.Textbox1
W = D * 2
Me.Textbox2 = W
End Sub

All I have here is "W=D*2" for a formula. You replace it with whatever formula you want. Remember, you have to declare all variables.

Good Luck.
Jul 3 '06 #2
nedian
4 New Member
Thanks for guiding me, but i am still encountering some problem.I will be really greatful if u guide me more.

what u have told me i have tried that but it is not completed without errors.let me tell u what i have done so far then i will tell u where i am having problem.

First of all i have created a table in which i have taken 3 entities.

1) Id ( primary key).(i have taken this enitity because a primary key is must for any table)
2) D
3) T

The next thing which i have done is: i have created a form by using design view.

u told me that
"create a form by using two textboxes( name them textbox1 and textbox2) and a Command button (name it btnCalculate). Right Click on the Command Button, and click "Build Event". Choose "Code Builder", and the code window will open, with the following code:"

Now my question is that when i created the first textbox, by clicking on the textbox button and then clicking on the form there appereared two boxes. the one with a transparent box inside which is written textbox0( i then changed the name, and name it textbox1.) and the other box is a white box inside which it is written "unbound" . In the same manner i have created two other textboxes and named it textbox2 and textbox3.

I have also created a Command button as per your instructions and when the code window is opened. i finished writing the code which appeared as follows.
Private Sub btnCalculate_click( )
Dim D,Dim T,W As Integer
D = Me.Textbox1
T = Me.Textbox2
W = 4.85 * T(D - T)
Me.Textbox3 = W
End Sub

when i runned that it is showing me error on second line

Dim D,Dim T,W As Integer

and this line appears in red.

Now what should i do.i have declared the variables D and T as u told me.but it is not accepting the variable T, i don't know why.

I am simply trying to make a program in which there are two variables D and T and the values of D and T are saved in a table. and this programs helps me to calculate the value of W (formula of W=4.85*T(D-T) ) whenever i give the value of D without giving the value of T with it.

i think "form" is not suitable for my program because in form when i have to calculate the value of W i have to give both the values of D and T and this is the thing which i don't want to do.

I am in dire need of further guidance.

Thanks
Jul 5 '06 #3
comteck
179 New Member
First of all, I'm not sure how familiar you are with Access. You might want to go online and do some of the online tutorials (there are many free ones). Here is one: http://www.functionx.com/vbaccess/.

But to get back to your problem. When you created your textbox, you said you got 2 textboxes (a transparent one, and a white box with the word "unbound". The transparent one is not actually a textbox. It is a label for the textbox that you created. You can click on just that label and delete it if you wish. It is the white box that must be renamed. You right click on it, and choose "Properties". Then put the name into the "Name" field (which is the first field under the "All" tab).

As for your red message that comes up for:
Dim D, Dim T, W, as Integer

Remove the second "Dim" word. It should only read:
Dim D, T, W as Integer

If it still doesn't accept the variables, you might have to assign a value to them initially. To do this, after your "Dim" statement, add this code:
D=0
T=0

And lastly, you said you don't think form is
Good Luck.

comteck
Jul 5 '06 #4
comteck
179 New Member
First of all, I'm not sure how familiar you are with Access. You might want to go online and do some of the online tutorials (there are many free ones). Here is one: http://www.functionx.com/vbaccess/.

But to get back to your problem. When you created your textbox, you said you got 2 textboxes (a transparent one, and a white box with the word "unbound". The transparent one is not actually a textbox. It is a label for the textbox that you created. You can click on just that label and delete it if you wish. It is the white box that must be renamed. You right click on it, and choose "Properties". Then put the name into the "Name" field (which is the first field under the "All" tab).

As for your red message that comes up for:
Dim D, Dim T, W, as Integer

Remove the second "Dim" word. It should only read:
Dim D, T, W as Integer

If it still doesn't accept the variables, you might have to assign a value to them initially. To do this, after your "Dim" statement, add this code:
D=0
T=0

And lastly, you said you don't think form is suitable because you don't want to enter the values of D and T. First of all, a form is used to make it more user friendly. You can use a form with any table or query in your database. And, a form is the only place you can put the button. So, yes, a form will definitely work. Secondly, where is it you want to get your values from? If you want to get them from pull down menus, then you have to use combo boxes instead of text boxes. Then, the code will be basically the same, but you will have to set up 2 more tables, and source those tables to your combo boxes.

If you were looking to use the pull down menus, let me know and I'll try and walk you through it.


Good Luck.
comteck
Jul 5 '06 #5
nedian
4 New Member
Thanks for your help, i am now able to calculate the value of W and my half task is done.

But the problem is that when i opened the form it is showing me the value of D and T both by itself (as it is stored in the table from which i am taking the data).and it is not asking the user to enter the value of D.

but what i want to do is that:

i want myself to enter the value of D in the form and want the form to show me the corresponding value of T (which is stored in the table on which the "form" is based on ) and when it showed me the value of T on the textbox then i proceed my work, of calculating the value of W by clicking on the btnCalculate.

Thanks again.
Jul 6 '06 #6

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

Similar topics

1
2671
by: Dim | last post by:
Hi, need some help/idea... I have data table in Excel(about 30 columns) and it's getting too big (over 65K) so I need to move it to DB (MS Access is the choice) one of the columns (for example...
7
2039
by: Helen | last post by:
vb .net 200 crystal reports Oracl Acces Hi, I have all selection formula results needed from the main crystal report, called in the vb form (Oracle db) I now need to build in the logic in...
0
1799
by: RJN | last post by:
Hi I have a main report and a sub report. I have a formula field on the main report and one on the sub report. I want the formula in the subreport to be evaluated after the formula in the main...
0
1605
by: RJN | last post by:
Hi Sorry for posting this message again. I have a main report and a sub report. I have a formula field on the main report and one on the sub report. I want the formula in the subreport to be...
0
2180
by: rjn | last post by:
Hi I have a main report in which I have inserted a sub report. I have a formula field on the main report and one on the sub report. I want the formula in the subreport to be evaluated after the...
1
5472
by: nedian | last post by:
Hello I am student and trying to learn access.I am having problem in making a program can any one help me? i wanted to make 2 tables in access and then create a link.First i am telling u what...
3
4225
by: skiddle | last post by:
I've got an Excel formula that calculates the total business hours that a help desk ticket is open. As one would expect, it factors out holidays and non-work hours. What would be the corresponding...
1
1456
by: DE529 | last post by:
Is there a way to override a formula in Access 2003? 90% of the time the formula fits with what I am needing, however there are times when I need to put in a different amount than what the formula...
2
2906
by: welshkaiboy | last post by:
Due to the size of the data I have to manipulate I need to apply a excel formula in access which determines date of manufacture from a serial number 716001 so I use...
0
7202
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
7086
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
7462
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
5578
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
4673
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
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1512
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
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
382
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.