473,396 Members | 2,106 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,396 software developers and data experts.

Using a query to populate an unbound text box on a form

kcdoell
230 100+
Hello:

I have a continous form that displays various forecasting records that an End user can add or edit the records (this feeds off of a query that I created called "ReQryForecast"). On that form, in the top corner, I placed 4 unbound text boxes that displays summary information. On one of them, "TxtBudGWP" I want to display the specific budget number for that particular month. This information is on a separate table I call tblbudget. I created a query called "QryBudget_Sum" that gives me the number I am looking for. Now I just want to populate that value into "TxtBudGWP" when the form opens.

I tried the following code in the before update event of TxtBudGWP:

Expand|Select|Wrap|Line Numbers
  1. Private Sub TxtBudGWP_BeforeUpdate(Cancel As Integer)
  2.  
  3. 'Set value of the text box to match the query...
  4.  
  5. 'Me.RecordSource = "GWP.tblbudget"
  6. 'Me.Filter = "QryBudget_Sum"
  7. 'Me.FilterOn = True
  8.  
  9. End Sub
But nothing happen when the form loaded. I am not too sure if this is the correct method of doing this.

Any idea?

Thanks,

Keith.
Apr 21 '08 #1
7 13481
kcdoell
230 100+
Good Morning:

I know this should be a no-brainer but I am stumped. I have done it with a listbox before where I point the row source to a query, but I believe I can do it with a text box as well but not using the same method.

Any ideas would be great..

Thanks,

Keith.
Apr 22 '08 #2
puppydogbuddy
1,923 Expert 1GB
Good Morning:

I know this should be a no-brainer but I am stumped. I have done it with a listbox before where I point the row source to a query, but I believe I can do it with a text box as well but not using the same method.

Any ideas would be great..

Thanks,

Keith.
Keith,
You can't directly use a query as a control source of a textbox; but you can accomplish the same thing using a domain aggregate function (DSum, etc). Secondly, you use the filter property the way you used it.,,,the filter property is used to filter records, not a control. Thirdly, the before and after update events are triggered by inputting changes to data, not by updates done in via programmed code. With the above in mind, below is one example of how you can pass the total to your textbox. Replace variable and object names used with their actual names in your application.
Expand|Select|Wrap|Line Numbers
  1. Private Sub YourInputTxtbox_AfterUpdate(Cancel As Integer)
  2. Dim budgetDetail As Currency
  3. Dim  budgetSum As Currency
  4.  
  5. 'Set value of the text box to match the query...
  6.  
  7. 'Me.RecordSource = "GWP.tblbudget"
  8. budgetSum = DSum(budgetDetail, "QryBudget_Sum")
  9. Me![TxtBudGWP] = budgetSum
  10.  
  11. End Sub
Apr 23 '08 #3
kcdoell
230 100+
Puppydogbuddy:

I inputted the following:
Expand|Select|Wrap|Line Numbers
  1. Private Sub TxtBudGWP_AfterUpdate()
  2. Dim GWP As Currency
  3. Dim GWPSUM As Currency
  4.  
  5. 'Set value of the text box to match the query...
  6.  
  7.     GWPSUM = DSum(GWP, "QryBudget_Sum")
  8.     Me![TxtBudGWP] = GWPSUM
  9.  
  10. End Sub
  11.  
But nothing happens when I open the form in TxtBudGWP. Even when I key in and out of it, it will populate a zero if I plugged in a number.

So the way I understand this, is even if I left out the above VB and just went into the control source of TxtBudGWP and placed in the following code:

Expand|Select|Wrap|Line Numbers
  1. DSum(GWP, "QryBudget_Sum")
  2.  
That still would not do the trick... I actually tryed this and got a "#Name?" in the text box field.

My table = tblbudget
Field name on the table and query = GWP
Query Name = QryBudget_Sum
Unbound text box on form = TxtBudGWP

Any additional thoughts on where I am going wrong?

Thanks,

Keith.
Apr 23 '08 #4
kcdoell
230 100+
Puppydogbuddy:

I inputted the following:
Expand|Select|Wrap|Line Numbers
  1. Private Sub TxtBudGWP_AfterUpdate()
  2. Dim GWP As Currency
  3. Dim GWPSUM As Currency
  4.  
  5. 'Set value of the text box to match the query...
  6.  
  7.     GWPSUM = DSum(GWP, "QryBudget_Sum")
  8.     Me![TxtBudGWP] = GWPSUM
  9.  
  10. End Sub
  11.  
But nothing happens............
I am getting closer I was missing quotes around GWP:

Expand|Select|Wrap|Line Numbers
  1. GWPSUM = DSum("GWP", "QryBudget_Sum")
Now when I click in the box and out the correct number populates. But I still want it to load when the form opens or when the form is requery...

Keith.
Apr 23 '08 #5
puppydogbuddy
1,923 Expert 1GB
I am getting closer I was missing quotes around GWP:

Expand|Select|Wrap|Line Numbers
  1. GWPSUM = DSum("GWP", "QryBudget_Sum")
Now when I click in the box and out the correct number populates. But I still want it to load when the form opens or when the form is requery...

Keith.
Keith,
Call the AfterUpdate code in the form open event as shown:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel as Integer)
  2. TxtBudGWP_AfterUpdate
  3. End Sub
As previously stated the update events don't fire if the update is done by code and not by input....so you have to call it directly by invoking the procedure name.
Apr 23 '08 #6
puppydogbuddy
1,923 Expert 1GB
PS: If GWP is a variable, remove the quotes.....
Apr 23 '08 #7
kcdoell
230 100+
PS: If GWP is a variable, remove the quotes.....

Puppydogbuddy:

It looks like I solved it with your help and some reading.

I cleared out the vb code of my unbound text box's event and place the following code into the control source:

Expand|Select|Wrap|Line Numbers
  1. =DSum("[GWP]","QryBudget_Sum")
In the end a simple solution but this seems to have done the trick.

Thanks for the help and insight.

Keith.
Apr 23 '08 #8

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

Similar topics

1
by: Matt | last post by:
OK, this has me mad and totally stumped. I have a query that queries one Oracle table (linked). I wish to limit the query on the PROBLEM_ID record by using a value enter via a form. I have a...
1
by: longtim | last post by:
I have been having endless difficulty creating reports/queries that set any relevent parameters from controls in forms. I am creating an application under access 2003 but will target access...
7
by: John | last post by:
I currently have a form and subform based on two tables; tblGoodsIn and tblGoodsInDetail. The fields in the underlying tables do not contain any price information. only foreign key links to...
2
by: Zlatko Matić | last post by:
Hello. I have the following problem with MS Access/PostgreSQL combination: There is a form in Access that has an unbound text box, used for entering a commentary of a batch of records. There is a...
9
by: gwww | last post by:
I have two fields on a form called Employee Name and Employee Number. I would like the user to select their name and their coresponding number will appear in the Employee Number field. The...
31
by: DWolff | last post by:
I'm somewhat new to Access, and have no VB experience at all (except for modifying existing code where obvious). I built a data entry form that works fine. Typically, a client will call in and...
10
by: mbatestblrock | last post by:
I dont know if this is possible.. I have a form frmCustomers with a subform sfrmCustomers and in the subform I have a unbound text field in the footer txtCOUNT with the control source of ...
11
by: jwessner | last post by:
I have a form (Form1) which contains basic Project data and a subform listing the personnel assigned to the Project as a continuous form. Selecting a person on that project and clicking on a command...
7
by: HSXWillH | last post by:
I am designing an inventory system and am stuck on a potential problem. I have a table of Stock_Catalog containing the following fields: Stock_ID (random autonumber), Full_Desc, Serial, Auto,...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.