dbTalk Databases Forums  

fill textbox from query

comp.databases.ms-access comp.databases.ms-access


Discuss fill textbox from query in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
RCGUA
 
Posts: n/a

Default fill textbox from query - 07-27-2009 , 04:45 PM






I have a text box that needs to be filled / populated with the Sum of
all the payments made by the worker selected in the combo box. The
following query will get the Sum based on whatever is selected in the
combo box:

SELECT DISTINCTROW Sum(tblPayments.PaymentAmount) AS
SumOfPaymentAmount
FROM tblPayments
WHERE (((tblPayments.WorkerName)=[frmCASA-4payments]!
[cboWorkerName]));

How do I get those query results into the text box, or get the Sum
based on the combo selection into the textbox.

I can requery the text box every time the combo box changes, if I can
get the sum in the text box.

Reply With Quote
  #2  
Old   
Salad
 
Posts: n/a

Default Re: fill textbox from query - 07-27-2009 , 05:38 PM






RCGUA wrote:

Quote:
I have a text box that needs to be filled / populated with the Sum of
all the payments made by the worker selected in the combo box. The
following query will get the Sum based on whatever is selected in the
combo box:

SELECT DISTINCTROW Sum(tblPayments.PaymentAmount) AS
SumOfPaymentAmount
FROM tblPayments
WHERE (((tblPayments.WorkerName)=[frmCASA-4payments]!
[cboWorkerName]));

How do I get those query results into the text box, or get the Sum
based on the combo selection into the textbox.

I can requery the text box every time the combo box changes, if I can
get the sum in the text box.
Assumes your field name is called TextFld. In the form's module you
might have.

Private Function GetSum()
Dim r As Recordset
Dim s As String
s = "Select ...." 'your above select. Or else queryname
Set r = Currentdb.Openrecordset(s,dbopensnapshot)
If r.recordcount > 0 then
Me.TextFld = r!SumOfPaymentAmount
else
Me.TextFld = 0
Endif
r.close
set r = nothing
End Function

Then in the control source enter
=GetSum()

You might need to enter some code like
Me.TextFld.Requery
in some event that trips the need to resum.

Reply With Quote
  #3  
Old   
RCGUA
 
Posts: n/a

Default Re: fill textbox from query - 07-27-2009 , 06:18 PM



On Jul 27, 5:38*pm, Salad <o... (AT) vinegar (DOT) com> wrote:
Quote:
RCGUA wrote:
I have a text box that needs to be filled / populated with the Sum of
all the payments made by the worker selected in the combo box. *The
following query will get the Sum based on whatever is selected in the
combo box:

SELECT DISTINCTROW Sum(tblPayments.PaymentAmount) AS
SumOfPaymentAmount
FROM tblPayments
WHERE (((tblPayments.WorkerName)=[frmCASA-4payments]!
[cboWorkerName]));

How do I get those query results into the text box, or get the Sum
based on the combo selection into the textbox.

I can requery the text box every time the combo box changes, if I can
get the sum in the text box.

Assumes your field name is called TextFld. *In the form's module you
might have.

Private Function GetSum()
Dim r As Recordset
Dim s As String
s = "Select ...." 'your above select. Or else queryname
Set r = Currentdb.Openrecordset(s,dbopensnapshot)
If r.recordcount > 0 then
* * * * *Me.TextFld = r!SumOfPaymentAmount
else
* * * * Me.TextFld = 0
Endif
r.close
set r = nothing
End Function

Then in the control source enter
* * * * =GetSum()

You might need to enter some code like
* * * * Me.TextFld.Requery
in some event that trips the need to resum.
I tried putting the query in like this (below), but it didn't seem to
"r" correctly because after that the code just stopped without an
error message and it didn't seem to have a record count.

Private Function GetSum()
Dim r As Recordset
Dim s As String
s = "qrySumOfEmployeePayments" 'your select Or else queryname
Set r = CurrentDb.OpenRecordset(s, dbOpenSnapshot)
If r.RecordCount > 0 Then
Me.txtTotalEmployeePayments = r!s ' SumOfPaymentAmount
Else
Me.txtTotalEmployeePayments = 0
End If
r.Close
Set r = Nothing
End Function

Reply With Quote
  #4  
Old   
Larry Linson
 
Posts: n/a

Default Re: fill textbox from query - 07-27-2009 , 06:32 PM



Use the Query Builder to build a Select Query that returns all the payments
made by each worker. Then, in design view, click View | Totals, on the
menu. Group by Worker ID, and set Sum on the amount. Use it as the domain
in a DSUM function, and refer to the TextBox on the Form showing the Worker
ID in the criteria argument. There's pretty good Help on DSUM... use the
Help on a Module window.

Larry Linson
Microsoft Office Access MVP

"RCGUA" <stv.nelson1 (AT) gmail (DOT) com> wrote

On Jul 27, 5:38 pm, Salad <o... (AT) vinegar (DOT) com> wrote:
Quote:
RCGUA wrote:
I have a text box that needs to be filled / populated with the Sum of
all the payments made by the worker selected in the combo box. The
following query will get the Sum based on whatever is selected in the
combo box:

SELECT DISTINCTROW Sum(tblPayments.PaymentAmount) AS
SumOfPaymentAmount
FROM tblPayments
WHERE (((tblPayments.WorkerName)=[frmCASA-4payments]!
[cboWorkerName]));

How do I get those query results into the text box, or get the Sum
based on the combo selection into the textbox.

I can requery the text box every time the combo box changes, if I can
get the sum in the text box.

Assumes your field name is called TextFld. In the form's module you
might have.

Private Function GetSum()
Dim r As Recordset
Dim s As String
s = "Select ...." 'your above select. Or else queryname
Set r = Currentdb.Openrecordset(s,dbopensnapshot)
If r.recordcount > 0 then
Me.TextFld = r!SumOfPaymentAmount
else
Me.TextFld = 0
Endif
r.close
set r = nothing
End Function

Then in the control source enter
=GetSum()

You might need to enter some code like
Me.TextFld.Requery
in some event that trips the need to resum.
I tried putting the query in like this (below), but it didn't seem to
"r" correctly because after that the code just stopped without an
error message and it didn't seem to have a record count.

Private Function GetSum()
Dim r As Recordset
Dim s As String
s = "qrySumOfEmployeePayments" 'your select Or else queryname
Set r = CurrentDb.OpenRecordset(s, dbOpenSnapshot)
If r.RecordCount > 0 Then
Me.txtTotalEmployeePayments = r!s ' SumOfPaymentAmount
Else
Me.txtTotalEmployeePayments = 0
End If
r.Close
Set r = Nothing
End Function

Reply With Quote
  #5  
Old   
RCGUA
 
Posts: n/a

Default Re: fill textbox from query - 07-28-2009 , 08:53 AM



On Jul 27, 6:32*pm, "Larry Linson" <boun... (AT) localhost (DOT) not> wrote:
Quote:
Use the Query Builder to build a Select Query that returns all the payments
made by each worker. *Then, in design view, click View | Totals, on the
menu. *Group by Worker ID, and set Sum on the amount. Use it as the domain
in a DSUM function, and refer to the TextBox on the Form showing the Worker
ID in the criteria argument. There's pretty good Help on DSUM... use the
Help on a Module window.

*Larry Linson
*Microsoft Office Access MVP

"RCGUA" <stv.nels... (AT) gmail (DOT) com> wrote in message

news:f4084d56-7631-4322-80c1-0bc7cbb221bf (AT) v36g2000yqv (DOT) googlegroups.com...
On Jul 27, 5:38 pm, Salad <o... (AT) vinegar (DOT) com> wrote:





RCGUA wrote:
I have a text box that needs to be filled / populated with the Sum of
all the payments made by the worker selected in the combo box. The
following query will get the Sum based on whatever is selected in the
combo box:

SELECT DISTINCTROW Sum(tblPayments.PaymentAmount) AS
SumOfPaymentAmount
FROM tblPayments
WHERE (((tblPayments.WorkerName)=[frmCASA-4payments]!
[cboWorkerName]));

How do I get those query results into the text box, or get the Sum
based on the combo selection into the textbox.

I can requery the text box every time the combo box changes, if I can
get the sum in the text box.

Assumes your field name is called TextFld. In the form's module you
might have.

Private Function GetSum()
Dim r As Recordset
Dim s As String
s = "Select ...." 'your above select. Or else queryname
Set r = Currentdb.Openrecordset(s,dbopensnapshot)
If r.recordcount > 0 then
Me.TextFld = r!SumOfPaymentAmount
else
Me.TextFld = 0
Endif
r.close
set r = nothing
End Function

Then in the control source enter
=GetSum()

You might need to enter some code like
Me.TextFld.Requery
in some event that trips the need to resum.

I tried putting the query in like this (below), but it didn't seem to
"r" correctly because after that the code just stopped without an
error message and it didn't seem to have a record count.

Private Function GetSum()
Dim r As Recordset
Dim s As String
s = "qrySumOfEmployeePayments" 'your select Or else queryname
Set r = CurrentDb.OpenRecordset(s, dbOpenSnapshot)
If r.RecordCount > 0 Then
* * * * *Me.txtTotalEmployeePayments = r!s *' SumOfPaymentAmount
Else
* * * * Me.txtTotalEmployeePayments = 0
End If
r.Close
Set r = Nothing
End Function- Hide quoted text -

- Show quoted text -
I tried both methods described above and I must be doing something
wrong with the syntax or some little thing. I have tried every which
way and I still cannot get the textbox to show the sum. At best, I
get "Name?" in the textbox where the query is running but not picking
up the name from the query.

The database is available on the Internet, if that helps. It's at:
http://manoamano.org/casa4/casa-4_v6.mdb

On the form named "frmCASA-4payments", right below the "Employee
Payments" box, there is a "Total Employee Payments" box, that is the
textbox I cannot seem to get the Sum of the payments for the worker
when the "Worker Name" combo box is updated.

Reply With Quote
  #6  
Old   
RCGUA
 
Posts: n/a

Default Re: fill textbox from query - 07-28-2009 , 09:12 AM



On Jul 28, 8:53*am, RCGUA <stv.nels... (AT) gmail (DOT) com> wrote:
Quote:
On Jul 27, 6:32*pm, "Larry Linson" <boun... (AT) localhost (DOT) not> wrote:





Use the Query Builder to build a Select Query that returns all the payments
made by each worker. *Then, in design view, click View | Totals, on the
menu. *Group by Worker ID, and set Sum on the amount. Use it as the domain
in a DSUM function, and refer to the TextBox on the Form showing the Worker
ID in the criteria argument. There's pretty good Help on DSUM... use the
Help on a Module window.

*Larry Linson
*Microsoft Office Access MVP

"RCGUA" <stv.nels... (AT) gmail (DOT) com> wrote in message

news:f4084d56-7631-4322-80c1-0bc7cbb221bf (AT) v36g2000yqv (DOT) googlegroups.com....
On Jul 27, 5:38 pm, Salad <o... (AT) vinegar (DOT) com> wrote:

RCGUA wrote:
I have a text box that needs to be filled / populated with the Sum of
all the payments made by the worker selected in the combo box. The
following query will get the Sum based on whatever is selected in the
combo box:

SELECT DISTINCTROW Sum(tblPayments.PaymentAmount) AS
SumOfPaymentAmount
FROM tblPayments
WHERE (((tblPayments.WorkerName)=[frmCASA-4payments]!
[cboWorkerName]));

How do I get those query results into the text box, or get the Sum
based on the combo selection into the textbox.

I can requery the text box every time the combo box changes, if I can
get the sum in the text box.

Assumes your field name is called TextFld. In the form's module you
might have.

Private Function GetSum()
Dim r As Recordset
Dim s As String
s = "Select ...." 'your above select. Or else queryname
Set r = Currentdb.Openrecordset(s,dbopensnapshot)
If r.recordcount > 0 then
Me.TextFld = r!SumOfPaymentAmount
else
Me.TextFld = 0
Endif
r.close
set r = nothing
End Function

Then in the control source enter
=GetSum()

You might need to enter some code like
Me.TextFld.Requery
in some event that trips the need to resum.

I tried putting the query in like this (below), but it didn't seem to
"r" correctly because after that the code just stopped without an
error message and it didn't seem to have a record count.

Private Function GetSum()
Dim r As Recordset
Dim s As String
s = "qrySumOfEmployeePayments" 'your select Or else queryname
Set r = CurrentDb.OpenRecordset(s, dbOpenSnapshot)
If r.RecordCount > 0 Then
* * * * *Me.txtTotalEmployeePayments = r!s *' SumOfPaymentAmount
Else
* * * * Me.txtTotalEmployeePayments = 0
End If
r.Close
Set r = Nothing
End Function- Hide quoted text -

- Show quoted text -

I tried both methods described above and I must be doing something
wrong with the syntax or some little thing. *I have tried every which
way and I still cannot get the textbox to show the sum. *At best, I
get "Name?" in the textbox where the query is running but not picking
up the name from the query.

The database is available on the Internet, if that helps. *It's at:http://manoamano.org/casa4/casa-4_v6.mdb

On the form named "frmCASA-4payments", right below the "Employee
Payments" box, there is a "Total Employee Payments" box, that is the
textbox I cannot seem to get the Sum of the payments for the worker
when the "Worker Name" combo box is updated.- Hide quoted text -

- Show quoted text -
===== Solved! ===== Thank you very much Larry & Salad for all your
help and pointing me in the right direction.=====

I set the control source for the textbox with the DSUM text below.
The Combo39 is a combo box that picks the Worker Name.

=DSum("[PaymentAmount]","tblPayments","[WorkerName] = Forms!
[frmCASA-4payments]!Combo39")

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.