473,748 Members | 10,048 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

detecting to calculate

dear all!!
i met the headache problem in setting value for some controls in my form.
i have 2 combo box in form F1.
i want to set value for some textbox in F1 when i choose value from 2
combo box.
the value calculated of these textbox base on some fields of table T1 in
condition: the same value between 2 combox-F1 and 2 fields-T1.
hereunder is my code:
Private Sub PACKAGE_AfterUp date()
Dim MyDB As Database
Dim MyRS As Recordset

Set MyDB = CurrentDb
Set MyRS = MyDB.OpenRecord set("T1", dbOpenSnapshot)
If Me!ContNo=MyRS. ContNo and Me!IDPro=MyRS!I DPro then
Me!QTITY = Me!PACKAGE * MyRS!PKG / MyRS!QTITY
Me!Price.value = MyRS!Price
End If
End Sub

it just find out the 1st row of table T1 and do the code.
but i want to find out though all the rows of T1, if they satisfy the
condition, they will do set value as the code.
any loop are there or ideas abt solving this !!
i get the help from Tom but it seem not better because maybe i show my
question in bad words.
Pls give me a hand.
thanks

Sep 21 '06 #1
6 2095
luanhoxung wrote:
dear all!!
i met the headache problem in setting value for some controls in my form.
i have 2 combo box in form F1.
i want to set value for some textbox in F1 when i choose value from 2
combo box.
the value calculated of these textbox base on some fields of table T1 in
condition: the same value between 2 combox-F1 and 2 fields-T1.
hereunder is my code:
Private Sub PACKAGE_AfterUp date()
Dim MyDB As Database
Dim MyRS As Recordset

Set MyDB = CurrentDb
Set MyRS = MyDB.OpenRecord set("T1", dbOpenSnapshot)
If Me!ContNo=MyRS. ContNo and Me!IDPro=MyRS!I DPro then
Me!QTITY = Me!PACKAGE * MyRS!PKG / MyRS!QTITY
Me!Price.value = MyRS!Price
End If
End Sub

it just find out the 1st row of table T1 and do the code.
but i want to find out though all the rows of T1, if they satisfy the
condition, they will do set value as the code.
any loop are there or ideas abt solving this !!
i get the help from Tom but it seem not better because maybe i show my
question in bad words.
Pls give me a hand.
thanks
If your above example, you open the recordset and whatever record you
are sitting on is the value you use in your computations.

You might want to create a SQL statement for your recordset. Ex:
Dim strSQL As STring
'assume ContNo and IDPro as numeric. Surround with quotes
'if charater, # if dates.
strSQL = "Select PKG, QTITY From T1 " & _
"Where ContNo = " & Me.ContNo And " & _
"IDPro = " & Me.IDPro
Set MyRS = MyDB.OpenRecord set("T1", dbOpenSnapshot)
If MyRS.RecordCoun t 0 then
'record found. Assumes only 1 found
Me!QTITY = Me!PACKAGE * MyRS!PKG / MyRS!QTITY
Me!Price.value = MyRS!Price
Endif
MYRs.close
set MYRs = nothing
Sep 21 '06 #2
dear Salad !!
thanks for ur help !!
i nearly catch the good result.
but i get errored message "type mismatch"
i forgot that IDPro and ContNo are text(not numeric) !!
Pls show me the way how i can overcome the errored !!
thank u.
luan

Sep 22 '06 #3
hi Salad !!
i just sent u reply but i seeked my fail in our code !!
although, i get the trouble as the last paragraph that i said in my first
mail.
it just seem to find out the first row of the table "T1", and it set value
to the 2nd record of the form as the 1st one of the form.
---The action--------the result(QTITY of the form)
1/ ContNo:a1...... .. ok: it cal. as my intend
IDPro:b1
2/ ContNo:a2
IDPro:b2 .........it calculate base on value a1 & b1 of table T1.

i try to do with help of VBA but i cant see anycode that i need.
can u give ur idea of this !!
i try to do through last nigh
Pls give me a hand !!
thanks...
luan from cantho-vietnam

IDPro:b2

Sep 22 '06 #4
luanhoxung wrote:
dear Salad !!
thanks for ur help !!
i nearly catch the good result.
but i get errored message "type mismatch"
i forgot that IDPro and ContNo are text(not numeric) !!
Pls show me the way how i can overcome the errored !!
thank u.
luan
If your table is a string, surround by quotes. Ex:
Dim var As String
var = "test"
"Where Fieldname = '" & var & "'"
or
"Where Fieldname = """ & var & """"
Check that out in a debug window.

If numeric
Dim var As Long
var = 2
"Where Fieldname = " & var

If Date
Dim var As Date
var = Date()
"Where Fieldname = #" & var & "#"

In the debug window, enter something like
var = Date()
? "Where Fieldname = #" & var & "#"

Sep 22 '06 #5
luanhoxung wrote:
hi Salad !!
i just sent u reply but i seeked my fail in our code !!
although, i get the trouble as the last paragraph that i said in my first
mail.
it just seem to find out the first row of the table "T1", and it set value
to the 2nd record of the form as the 1st one of the form.
---The action--------the result(QTITY of the form)
1/ ContNo:a1...... .. ok: it cal. as my intend
IDPro:b1
2/ ContNo:a2
IDPro:b2 .........it calculate base on value a1 & b1 of table T1.

i try to do with help of VBA but i cant see anycode that i need.
can u give ur idea of this !!
i try to do through last nigh
Pls give me a hand !!
thanks...
luan from cantho-vietnam

IDPro:b2
You stated earlier:
>i have 2 combo box in form F1.
Let's call them Combo1 and Combo2 in my response. Substitue for what
you have.
>i want to set value for some textbox in F1 when i choose value from 2
combo box.
>the value calculated of these textbox base on some fields of table T1
in condition: the same value between 2 combox-F1 and 2 fields-T1.

So you want to create a value for a form's Price field once you have
selected values from the combo field and the Package field.

In the Package_BeforeU pdate() routine you could enter
If IsNull(Me.Combo 1) Or IsNull(Me.Combo 2) Then
msgbox "Please select items from both combo boxes"
Cancel = True
Endif

This will stop the calculation process until both Combo1 and Combo2 have
values selected.

Now let's look at the following code, using stuff from my prior post.

Private Sub PACKAGE_AfterUp date()
Dim MyRS As Recordset
Dim strSQL As String

'build SQL statement to select record that
'matches the ContNo and IDPro.
strSQL = "Select PKG, QTITY, Price From T1 " & _
"Where ContNo = '" & Me.ContNo & "' And " & _
"IDPro = '" & Me.IDPro & "'"

'next line for debugging purposes. Comment out
'if you'd like.
Msgbox strSQL

'open up the recordset
Set MyRS = Currentdb.OpenR ecordset(strSQL , dbOpenSnapshot)

If MyRS.RecordCoun t 0 then
'record found. Assumes only 1 found
Me!QTITY = Me!PACKAGE * MyRS!PKG / MyRS!QTITY
Me!Price = MyRS!Price
Else
msgbox "Record to calculate not found."
Me.QTity = 0
Me.Price = 0
Endif
MYRs.close
set MYRs = nothing
End Sub

Sep 22 '06 #6
hi Salad !!
great help!!
many many many with thanks !!
u pulled me from marsh.
in spite of, there still have a small problem.
I think i can solve it alone.

thanks !!
hope see u in other harder question !! :-)

Sep 23 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
12587
by: Jole | last post by:
Hi I'm writing a program that needs to read from a file. In order for the program to be robust, it should somehow check that the file isn't corrupt, or stuffed in any way. For example, that file may have been created but a crash occurred at that point in time (while it was being created), damaging the file. Now, my program which needs to read from this file, should first check that it's in good condition, and that it hasn't been...
15
2699
by: Jay | last post by:
I'm sure this is a really dumb question, but how do you detect a variable type in Python? For example, I want to know if the variable "a" is a list of strings or a single string. How do I do this?
3
1856
by: raptor | last post by:
hi, how to detect opera..it seems that even opera8 doesnt support xmlhttp fully (.i.e. sendRequestHeader). I ask this 'cause opera seems to mimic IE, at least in the preferences ?! I havent used opera till now, but it seems very buggy piece of software !! I have one very annoyng problem, fighting already ~4 hours. I found that if I use something like this in table (test are
1
7784
by: Hadi | last post by:
Hello, I have to DateTime structure, how do I calculate if date A is on the same week with date B or last week of date B? Thanks, Hadi
9
2019
by: D. Shane Fowlkes | last post by:
I'm using SQL Server 2000 and on my page, I'm simply creating a SQLDataReader and filling in Labels with the retrieved (single) record. However, how can I prevent from getting errors when a field is null? I've tried something like this (experimenting with IsDBNull): ========================================================= If dtrData.IsDBNull("Address2") = True Then lblAddress2.Text = "" Else
3
3611
by: regtrashcan | last post by:
I have a webpage that detects whether Shockwave Player is installed and the version number. The javascript/vbscript that I use has worked fine until the latest release of the Shockwave Player. I am still able to detect the Shockwave Player and the version number when using Firefox/Netscape, but not with IE. I have my own detection script that I use, but I've also used the detection scripts supplied from Macromedia, but it still won't...
79
3778
by: VK | last post by:
I wandering about the common proctice of some UA's producers to spoof the UA string to pretend to be another browser (most often IE). Shouldn't it be considered as a trademark violation of the relevant name owner? If I make a whisky and call it "Jack Daniels", I most probably will have some serious legal problems. "Mozilla" partially appeared because NCSA stopped them from using "Mosaic" in the UA string. Is it some different...
5
8774
by: Z.K. | last post by:
In C#, using the StreamReader, how do I detect when you get to the end of line. I am reading a text file using the Read() function and I need to detect the \n\r, but everything I try does not work. I am sure that this probably fairly simple, but I have not been able to figure it out. Z.K.
1
24173
by: wwwords | last post by:
Is there a general method for detecting that a user has changed the record currently visible on a form, whether this is by hitting PgUp or PgDn or clicking on a navigation button, even if no change has been made in any control? I'm thinking of a situation in which a number of records have been entered on a form and the user is cycling through them to check the data entered. I want to be able to detect this and update certain information...
0
8989
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9367
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8241
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6795
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4599
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4869
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3309
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 we have to send another system
3
2213
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.