473,416 Members | 1,597 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,416 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 5798
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...
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
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.