472,992 Members | 3,418 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,992 software developers and data experts.

Combo box after update event

I have a combo box called "Recipient" who's row source is a table called
"Main" with three columns. The three columns are "Name", "Floor", "Location".
Following the combo box are two fields called "Floor" and "Location". The
after update event of the combo box runs the following lines to update the
next two fields.

[Floor] = Recipient.Column(2)
[Location] = Recipient.Column(3)

The combo box is not limited to the values in its rowsource table. What I
want is that if the value entered in the combo box is not in its rowsource it
should update the next two fields as follows.

[Floor] = "1"
[Location] = "?"

I tried the following code and it gives me the error "You canceled the
previous operation".

if DCount("*", "Main", "[Name]=" & me.Recipient)< 1 then
[Floor]="1"
[Location]="?"
else
[Floor] = Recipient.Column(2)
[Location] = Recipient.Column(3)
end if.

--
Message posted via http://www.accessmonster.com

Aug 28 '07 #1
4 5769
ARC
Do you have an add/edit form that allows changes to the table that stores
Name/Floor/Location? If so, you could just do a not in list event that opens
the add/edit form to a new record. Something like:

Private Sub SalesInitID_NotInList(NewData As String, Response As Integer)
If MsgBox("The Sales Person Initials you entered could not be found. Would
you like to add it now?", vbYesNo + vbInformation, "Item Not Found - Add?")
= vbYes Then
DoCmd.OpenForm "SalesInitials", , , , acFormAdd
Forms!SalesInitials.Form!SalesInitials = NewData
End If
Response = acDataErrContinue
Me!SalesInitID.Undo
DoCmd.CancelEvent
End Sub
Aug 28 '07 #2
On Aug 28, 3:55 pm, "injanib via AccessMonster.com" <u35551@uwe>
wrote:
I have a combo box called "Recipient" who's row source is a table called
"Main" with three columns. The three columns are "Name", "Floor", "Location".
Following the combo box are two fields called "Floor" and "Location". The
after update event of the combo box runs the following lines to update the
next two fields.

[Floor] = Recipient.Column(2)
[Location] = Recipient.Column(3)

The combo box is not limited to the values in its rowsource table. What I
want is that if the value entered in the combo box is not in its rowsource it
should update the next two fields as follows.

[Floor] = "1"
[Location] = "?"

I tried the following code and it gives me the error "You canceled the
previous operation".

if DCount("*", "Main", "[Name]=" & me.Recipient)< 1 then
[Floor]="1"
[Location]="?"
else
[Floor] = Recipient.Column(2)
[Location] = Recipient.Column(3)
end if.

--
Message posted viahttp://www.accessmonster.com
Insure the "Limit to list" property for Recipient is True then:

Private Sub Recipient_NotInList(NewData As String, Response As
Integer)
Me.Floor.Value = "1"
Me.Location.Value = "?"
Response = acDataErrContinue
End Sub

You'll have to add some if you then want the updated fields to be
added to the drop-down list or add them to the table.

Aug 29 '07 #3
this works, but I can not make the focus to leave Recipient field. Not even
by clicking else where.

DTecMeister wrote:
>On Aug 28, 3:55 pm, "injanib via AccessMonster.com" <u35551@uwe>
wrote:
>I have a combo box called "Recipient" who's row source is a table called
"Main" with three columns. The three columns are "Name", "Floor", "Location".
[quoted text clipped - 25 lines]
>--
Message posted viahttp://www.accessmonster.com

Insure the "Limit to list" property for Recipient is True then:

Private Sub Recipient_NotInList(NewData As String, Response As
Integer)
Me.Floor.Value = "1"
Me.Location.Value = "?"
Response = acDataErrContinue
End Sub

You'll have to add some if you then want the updated fields to be
added to the drop-down list or add them to the table.
--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200708/1

Aug 29 '07 #4
On Aug 29, 9:38 am, "injanib via AccessMonster.com" <u35551@uwe>
wrote:
this works, but I can not make the focus to leave Recipient field. Not even
by clicking else where.

DTecMeisterwrote:
On Aug 28, 3:55 pm, "injanib via AccessMonster.com" <u35551@uwe>
wrote:
I have a combo box called "Recipient" who's row source is a table called
"Main" with three columns. The three columns are "Name", "Floor", "Location".
[quoted text clipped - 25 lines]
--
Message posted viahttp://www.accessmonster.com
Insure the "Limit to list" property for Recipient is True then:
Private Sub Recipient_NotInList(NewData As String, Response As
Integer)
Me.Floor.Value = "1"
Me.Location.Value = "?"
Response = acDataErrContinue
End Sub
You'll have to add some if you then want the updated fields to be
added to the drop-down list or add them to the table.

--
Message posted via AccessMonster.comhttp://www.accessmonster.com/Uwe/Forums.aspx/databases-ms-access/2007...- Hide quoted text -

- Show quoted text -
I got it. You'll need to programmatically add the new row to the
table containing the rowsource information and set the fields with
default values:
Dim MyConnection As New ADODB.Connection
Dim AddSQL As New ADODB.Command
MyConnection.Open "DSN=Set_Me_to_your_ODBCCONNECTION"
MyConnection.CursorLocation = adUseClient
Set AddSQL.ActiveConnection = MyConnection
AddSQL.CommandText = "insert into Recipients values ('" + NewData +
"',''1,'?')"
AddSQL.Execute
Response = acDataErrAdded

I use linked tables so you may be able to do this without the odbc
connection, but you get the idea.

Aug 31 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: OhFiddleSticks | last post by:
Does anyone know if there is a way to add a text value to a combo box (the text box part, not the rowsource) in VBA without triggering an update event? I've tried everything I can think of without...
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...
6
by: Support4John | last post by:
a2k (9.0.6926) SP-3 Jet 4.0 SP-7 I have a form with combo box field that allows the user to select from the combo box or type in the field value that may or maynot be in the combo box field. ...
11
by: my-wings | last post by:
I think I've painted myself into a corner, and I'm hoping someone can help me out. I have a table of books (tblBooks), which includes a field (strPubName) for Publisher Name and another field...
9
by: Vmusic | last post by:
Hi, I'm using MS Access 2002. I have a form with a combo box built from a query that returns one column, and that one column is the bound column. How do you use VBA to programmatically change...
5
by: debbie | last post by:
I have three combo boxes on a subform. I have tried setting them up so that when the user clicks in the combo box the curser moves to the left. I have searched the posts and can find nothing that...
4
Rabbit
by: Rabbit | last post by:
Cascading Combo/List Boxes This tutorial is to guide you in the creation of Cascading combo/list boxes. That is when you have multiple combo/list boxes where the selection of an option in one...
6
by: Dave | last post by:
I want to put the information that the user selects in my combo boxes into a subform that lies on the same form as the combo boxes. Thanks for your help already, Dave
12
by: Richard Penfold | last post by:
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.