473,395 Members | 1,941 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,395 software developers and data experts.

Trying to update a combo box using a command button or report event

I have a form with a subform containing the combo box I want to update. I have a command button in the header of the main form that launches a report in print preview mode. I want to update the combo box from 'New' to 'Confirmed' when the report is generated. I have tried the following code in both the buttons on_click event and in the reports on_close event (security is set to trust the db)
Expand|Select|Wrap|Line Numbers
  1. Forms![Transactions]![Transaction Details Subform].[Form]![OrderStatusID]="1"
There are no errors but it does not work.
Can someone help.
NB: There is a one-to-many relationship between the underlying tables of the main and sub forms so multiple instances of the combo box may appear on the form - All need to be updated.
Jun 13 '09 #1
12 2112
DonRayner
489 Expert 256MB
Your syntax is slightly off.
Expand|Select|Wrap|Line Numbers
  1. Forms![Transactions]![Transaction Details Subform].[Form]![OrderStatusID]="1"
  2.  
should be

Expand|Select|Wrap|Line Numbers
  1. Forms![Transactions].Form![Transaction Details Subform]![OrderStatusID]="Confirmed"
  2.  
Jun 15 '09 #2
NeoPa
32,556 Expert Mod 16PB
Can you perhaps share with us how this ComboBox is set up Richard?

We don't really have enough info to determine what your problem may be. .RowSource, .ColumnCount, .ColumnWidths & .BoundColumn properties would be most helpful to start with.
Jun 15 '09 #3
NeoPa
32,556 Expert Mod 16PB
@DonRayner
I'm sorry Don. I feel you may be mistaken here.

Check out Referring to Items on a Sub-Form. The .Form property is relative to the SubForm control.
Jun 15 '09 #4
Many thanks for the help so far.
NeoPa
The Combo Box control details are as follows:
Control Source = Transactions.OrderStatusID
Row Source = SELECT [Order Status].ID, [Order Status].OrderStatus FROM [Order Status];
Format: Column Count = 2: Column Width = 0cm;2.5cm.

All
I have implemented the code suggested with one minor change as follows:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_Close()
  2. Forms![Transactions]![Transaction Details Subform]![OrderStatusID] = 2
  3. End Sub
This code updates one instance of the control on my form. There can be multiple instances however. As a simplified representation, the form looks like this...
Expand|Select|Wrap|Line Numbers
  1. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  2. Main Form
  3. CustomerName : OrderNumber : Date : Comments
  4.  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  5. Sub Form
  6. New: Qty : OrderCode : Description  
  7. New: Qty : OrderCode : Description  
  8. New: Qty : OrderCode : Description  
  9. ...etc
  10. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Where 'New' is the default value of the 'OrderStatusID' control I want to update

When I run the code (close the report) I get this...
Expand|Select|Wrap|Line Numbers
  1. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  2. Main Form
  3. CustomerName : OrderNumber : Date : Comments
  4.  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  5. Sub Form
  6. Confirmed  : Qty : OrderCode : Description  
  7. New        : Qty : OrderCode : Description  
  8. New        : Qty : OrderCode : Description  
  9. ...etc
  10. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
A customer may request many items on any one order. - I want to confirm all of them at once.
Jun 16 '09 #5
NeoPa
32,556 Expert Mod 16PB
Ah. That's quite a different question then (at least a fundamentally different answer now the question is clearer).

For this you will want instead, to update the records in the table (using some simple SQL) and then call a .Requery of the subform.

We don't have the details of any filtering or linking that restricts the data on your subform, but you will need to design SQL to reflect the same records in your update query (SQL).

If you need help with this then please reply including the info we would need to be able to show this for you.
Jun 18 '09 #6
Thanks NeoPa. I'll give it a go myself over the weekend and let you know the outcome.
Jun 18 '09 #7
NeoPa
32,556 Expert Mod 16PB
Please do Richard.

Good luck :)
Jun 19 '09 #8
Hi,
After much brain wracking I have to admit defeat. Can you tell me what's wrong with this...
Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_Close()
  2. Update [Transaction Details] Set OrderStatusID = 2
  3. WHERE ((([Transaction Details].TransactionID) = [Forms]![Transactions]![Transaction Details Subform].[Form]![TransactionID]))
  4. End Sub
I just get a syntax error.
I have tried various combinations of bracket types and quote marks. I also tried renaming the table to remove the space - Still no-go.
Jun 22 '09 #9
NeoPa
32,556 Expert Mod 16PB
Yes. I can.

Fundamentally you are trying to execute SQL code as VBA code.

I'll have a look at it and see what I can do, but you need to create your SQL string first using VBA, then pass that string to be executed as SQL.
Jun 22 '09 #10
NeoPa
32,556 Expert Mod 16PB
Try this :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_Close() 
  2.   Dim strSQL As String
  3.  
  4.   strSQL = "Update [Transaction Details] " & _
  5.            "Set OrderStatusID = 2 " & _
  6.            "WHERE [Transaction Details].TransactionID=" & _
  7.            [Forms]![Transactions]![Transaction Details Subform]![TransactionID]
  8.   Call CurrentDb.Execute(strSQL)
  9. End Sub
Jun 22 '09 #11
Hi NeoPa,
Your code works beautifully, many thanks.

I guess there is a VBA equivalent to the code I used but I did not find an example on the web. Does the "Dim nnn As String, nnn = and Call" wrapper to sql code work in all such instances?
Jun 22 '09 #12
NeoPa
32,556 Expert Mod 16PB
It should work for all executable queries, yes.
Jun 23 '09 #13

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

Similar topics

1
by: Maria Joao | last post by:
I have two synchronized combo boxes and after the selection of the desired record, I need the user to open the related report, by pressing a button. My problem is that a combo box doesn't update...
4
by: Alex | last post by:
I have searched the boards but I have not found what I am looking for yet. I have a form with two combo boxes. When the user makes a selection in both of the combo boxes the information will...
2
by: Ray Todd Jr | last post by:
I have created form, query and report. In the form I have a Combo Box which pulls the search criteria (SaleStatus) from one of my tables. When I select a status and click on the search button...
14
by: Kevin | last post by:
A couple of easy questions here hopefully. I've been working on two different database projects which make use of multiple forms. 1. Where's the best/recommended placement for command buttons...
2
by: Senthil | last post by:
Hi All I need to create an Excel report and create a command button and have to run a macro on the click event that will print all the pages in the Excel workbook. I am able to create the report...
6
by: fieldja | last post by:
I have a form called OwnerForm. It contains a combo box called Owner. The combo box looks up names from a table called OwnerName. It contains fields called OwnerID and Owner. I also have a main...
2
by: ndeeley | last post by:
Hello, I need to create a command button to print a report in Preview mode using the criteria from a combo box. The combo box is unbound and holds a list of clients. I need the user to select...
3
by: gmazza via AccessMonster.com | last post by:
Hi there, I am trying to run a report using a parameter for where the user chooses a month from a combo box. Then on the report, I want it to compare the month to a date field and choose only...
9
by: sparks | last post by:
Right now I had to build a report that allowed the people to check for gross outliers in their data input. short I am looking at 2.5* std dev + - anyway I used 2 dummy variables in the query the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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
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.