Connecting Tech Pros Worldwide Forums | Help | Site Map

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

Newbie
 
Join Date: Jan 2009
Location: Melbourne - Australia
Posts: 24
#1: Jun 13 '09
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.

DonRayner's Avatar
Expert
 
Join Date: Sep 2008
Location: Canada
Posts: 494
#2: Jun 15 '09

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


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.  
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,722
#3: Jun 15 '09

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


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.
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,722
#4: Jun 15 '09

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


Quote:

Originally Posted by DonRayner View Post

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.  

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.
Newbie
 
Join Date: Jan 2009
Location: Melbourne - Australia
Posts: 24
#5: Jun 16 '09

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


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.
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,722
#6: Jun 18 '09

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


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.
Newbie
 
Join Date: Jan 2009
Location: Melbourne - Australia
Posts: 24
#7: Jun 18 '09

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


Thanks NeoPa. I'll give it a go myself over the weekend and let you know the outcome.
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,722
#8: Jun 19 '09

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


Please do Richard.

Good luck :)
Newbie
 
Join Date: Jan 2009
Location: Melbourne - Australia
Posts: 24
#9: Jun 22 '09

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


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.
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,722
#10: Jun 22 '09

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


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.
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,722
#11: Jun 22 '09

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


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
Newbie
 
Join Date: Jan 2009
Location: Melbourne - Australia
Posts: 24
#12: Jun 22 '09

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


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?
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,722
#13: Jun 23 '09

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


It should work for all executable queries, yes.
Reply