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_BeforeUpdate() routine you could enter
If IsNull(Me.Combo1) Or IsNull(Me.Combo2) 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_AfterUpdate()
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.OpenRecordset(strSQL, dbOpenSnapshot)
If MyRS.RecordCount 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