473,803 Members | 2,934 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using combobox for value input

Knut Ole
70 New Member
hi,
i have a combobox that pulls a list from a table, and i've added a "New" button to create a new blank record in the combobox (see below). when i have a new record (ID) in the combobox however, and want to fill that new recordset in, if the value i enter happens to be one that already exists in another record, it will CHOOSE that old record and make it "active," instead of filling in the new record with the new value...

so how do i make the combo box differentiate, ie. enter values into a new recordset even when those values happen to be similiar to already existing values?

Expand|Select|Wrap|Line Numbers
  1. Private Sub NewC(curComboText As String)
  2.  
  3.     Dim strMsg As String
  4.     Dim rstNewContact As DAO.Recordset
  5.  
  6.  
  7.     strMsg = "'" & curComboText & "' is not in the list.  "
  8.     strMsg = strMsg & "Would you like to make a new Contact with " & curComboText & " as last name?"
  9.  
  10.     If vbNo = MsgBox(strMsg, vbYesNo + vbQuestion + vbApplicationModal, "New Customer") Then
  11.       Response = acDataErrDisplay 'Access displays its standard Error Message
  12.       'nuContact = False
  13.     Else
  14.       'Decided to Add the New Customer
  15.       EditMode (True)
  16.       MsgBox "after editmode, curComboText=" & curComboText
  17.       Set rstNewContact = CurrentDb.OpenRecordset("Contacts", dbOpenTable)
  18.         With rstNewContact
  19.             .Index = "PrimaryKey"
  20. '            .Seek "=", comboID
  21. '            If .NoMatch = False Then
  22.                ' MsgBox "seek ok, " & comboID
  23.                 'strIndex = !LastName
  24.                ' MsgBox "last name is " & strIndex
  25.                 .MoveFirst
  26.                 .MoveLast
  27.                 .AddNew
  28.                 !LastName = curComboText
  29.                 .Update
  30.                 .MoveLast
  31.                 comboID = !ID
  32.                 .Seek "=", comboID
  33.                 MsgBox "nu comboid=" & comboID
  34.  
  35.                 Form_Query18.Combo336.Value = comboID
  36.                 Form_Query18.Combo336.Requery
  37.                 MsgBox "new contact added, " & !LastName & " + " & !FirstName
  38.  
  39. '            Else
  40. '            MsgBox "id not found?! "
  41.  '           End If
  42.         End With
  43.  
  44.         curID = rstNewContact("ID")
  45.         curLN = rstNewContact("LastName")
  46.         curMob = rstNewContact("Mobile")
  47.         'MsgBox curID & ", " & curLN & ", " & curMob & ", " & NewData & "+ " & varBookmark
  48.         Response = acDataErrAdded   'Item added to underlying Recordset and the Combo
  49.                                     'Box is Requeried, Item added to List
  50.         rstNewContact.Close
  51.         Set rstNewContact = Nothing
  52.         Form_Query18.Combo336.SetFocus
  53.         Form_Query18.Combo340.Requery
  54.         bTextCombo336 = ""
  55.     End If
  56.  
  57.  
  58.  
  59. End Sub
  60.  
new button create new record and adds perhaps the last name if available... (barely working code...)


thanks for any help..
Apr 9 '11 #1
8 3123
Knut Ole
70 New Member
i should mention i have three combo boxes (last name, first name, mobile number), and i'm having trouble with all three - if a add a new value to the first box, and the new ID is the same in all three, it will still move to a different recordset instead of adding new value if new value happens to be already existing. so the cb is selecting from its list, instead of adding new value?

i guess im expecting there to be some simple "setting" of the combobox i need to adjust, but perhaps i need to catch it with tab or enter button press, and edit current recordset manually?

thank
Apr 9 '11 #2
NeoPa
32,579 Recognized Expert Moderator MVP
This appears to be unconnected with the ComboBoxes per se, but all to do with the code you're associating with them.

If you want different behaviour from your code you will need to change the code (This seems too obvious to be what you're asking for but unless you want someone else to develop your work for you I see no other interpretation) .
Apr 10 '11 #3
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
When you are posting this amount of code, It would REALLY be preferable if you could omit the lines of code you have commented out.

Expand|Select|Wrap|Line Numbers
  1. Set rstNewContact = CurrentDb.OpenRecordset("Contacts", dbOpenTable)
  2.         With rstNewContact
  3.             .Index = "PrimaryKey"
  4.                 .MoveFirst
  5.                 .MoveLast
  6.                 .AddNew
  7.                 !LastName = curComboText
  8.                 .Update
  9.                 .MoveLast
  10.                 comboID = !ID
  11.                 .Seek "=", comboID
  12.                 MsgBox "nu comboid=" & comboID
  13.  
  14.                 Form_Query18.Combo336.Value = comboID
  15.                 Form_Query18.Combo336.Requery
  16.                 MsgBox "new contact added, " & !LastName & " + " & !FirstName
  17.  
You seem to have alot of code that has no real purpose.
You want to add a new record, so there would be no need to use .MoveFirst and .MoveLast.
Simply:
Expand|Select|Wrap|Line Numbers
  1. .AddNew
  2. !LastName=curComboText
  3. .Update
Why have the .MoveLast again after the update? If your ID field is autonumber I would THINK that you simply use:
Expand|Select|Wrap|Line Numbers
  1. comboID = !ID
There also seems no need to use a .Seek at that time.

There is also little point in setting the value of your forms combobox, before you have requery' it.

Expand|Select|Wrap|Line Numbers
  1. Form_Query18.Combo33.Undo
  2. Form_Query18.Combo33.Requery
  3. Form_Query18.Combo33.Value=comboID
And pretty please with sugar on top, give your querys and comboboxes a meaningfull name.

EDIT:
I also fail to see what
Response=AcData ErrContinue has of purpose in a procedure where Response has not been declared and is not part of the function. I strongly recommend that you add Option Explicit to the top line of your module!
Apr 11 '11 #4
Knut Ole
70 New Member
thanks for reply,
im sorry for posting messy code. as for superfluous code, thanks smileycoder, i'll look it up. the .movefirst/last is recommended by microsoft, however, to "populate the recordset." but i know but what i pick up here and there.

as for my question, i suppose your answer neopa is that there is no setting/function inherent in comboboxes that will make it differentiate between entering new values and looking up old ones. ok, thanks for the answer. i guess i was looking for a tips as to how to go about it, but i'll figure it out myself instead, as my question here is somehow deemed inappropriate.

thanks again.
Apr 12 '11 #5
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
Part of your trouble comes from copying code thats intended to be run from within the NotInList event. Thats for example where you got your Response variable idea from.

In your example you create a new record with the curComboText as the Lastname, but you never specify the Firstname. If you want to add a more complicated "new" record, the best approach (In my oppinion, mind you :)) is to use a form.

I have made a small example db, of how it can be performed using a couple of events and forms. Use frm_Example and start typing some name into the combobox.

If you have questions ask.

Regarding the .MoveLast vs. MoveFirst, as far as I know, the only reason to do that, is if you wish to make use of the .RecordCount property. Now Im self-taught in access and VBA myself, so don't always take my words as the truth. Being an expert just means I've made more mistakes then you!
Attached Files
File Type: zip NotInList.zip (43.1 KB, 119 views)
Apr 12 '11 #6
NeoPa
32,579 Recognized Expert Moderator MVP
Knut Ole:
i guess i was looking for a tips as to how to go about it, but i'll figure it out myself instead, as my question here is somehow deemed inappropriate.
To be able to offer tips I would need a better understanding of what you're after. The question isn't so much inappropriate, as unclear. Actually, my tip was possibly more helpful than you appreciate. It tells you at least where to focus your effort, which you didn't seem too clear about in your question.

If you follow the advice in the sticky threads about how to post your questions - what to include; what not to; keeping the question to a single question; etc - this will give us something more to work with technically.

I expect Smiley's post will have helped you more on the technical side, but feel free to indicate where you've got to if you need more assistance.

PS. .MoveLast/.MoveFirst is a technique that can be required, but only when it's important that the recordset be pre-populated (such as for when the record count is required). If that describes your logic then it's helpful. Often it's not required, but you would need to decide that for yourself knowing the exact logic you require.
Apr 12 '11 #7
Knut Ole
70 New Member
Thanks for your answers, I've been away for a couple of weeks.

I've indeed heeded the advice and made separate forms for entering the info. Thanks again for your excellent responses, they are highly appreciated! I deem you naught but angels of open-source-utopia, and I solemnly swear to improve my posts and code! Thank you again neopa and smiley!
Apr 28 '11 #8
NeoPa
32,579 Recognized Expert Moderator MVP
Good to hear Knut :-)

I hope (and expect) you find your questions get more and better answers as a result.
Apr 28 '11 #9

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

Similar topics

4
1528
by: Dianna K | last post by:
Hi, I am trying to set the value of the a combobox with a field from a dataset. It will not set. Me.cboTypeDesc.Text = DsTitle.Tables("Title").Rows(0).Item ("genre_description") or
1
7557
by: Goos van Beek | last post by:
Hello. I'm using the following code to fill a combobox on a Windows form: private void FillCboRelation(){ using(SqlCommand sqlStatement = new SqlCommand("sp_RelationList",cnn)) { using(SqlDataReader rdReader=sqlStatement.ExecuteReader()){ while(rdReader.Read()){ cboRelation.Items.Add(rdReader.ToString()); }//end while
9
7514
by: juli jul | last post by:
Hello ,I am trying to get the comboBox value but when I am writing: MessageBox.Show(this.comboBoxdb.SelectedValue.ToString()); I get the following result: System.Data.DataRowView instead of the selected value . Why? *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
1
2374
by: Filip Hendrickx | last post by:
Hi there. I want to generate elements, choosing the element name dynamically. So I tried to use attribute value templates: <xsl:element name="{$local-name($someNode)}"> <!-- Generate element content. --> </xsl:element> where $someNode is an XML tree.
1
1264
by: luthriaajay | last post by:
Using <xsl:value-of in XSL XML file <i:Details> <i:Stra> <stra:Desc>ABC</stra.Desc>
3
1453
by: rhepsi | last post by:
Hii all, How to join two tables and a combobox value?? i have 2 combo boxes and 2 tables i have aquery: 1) Dim myselectquery As String = "SELECT pr_project_id_pk FROM tbl_projects WHERE tbl_projects.pr_project_location= ?SName"
15
7287
by: rashmiraj | last post by:
can anyone help me to write the code to get a field from database using combobox and that should display the corresponding record in datagrid using vb6.0
3
1273
by: RhazeMondragon | last post by:
hello!!! i encounter problem by searching the records the database by using date value what would be the appropriate sql command that would fit in this problem.... thanks a lot!!!
1
2195
by: sjarmy | last post by:
I am using javascript to make a dropdownlist act like a combobox and it is work well. The issue I'm having is when the user types in the combobox and finds the selection he wants, he has to use the mouse to make the actual selection. The user wants to have the option of just hitting the enter key instead of using the mouse. He also wants to use the tab key to move to the next field. I'm using onkeydown to call the javascript, and I know I need...
1
1302
by: rajanji | last post by:
Hi all , I am new to ASP.NET and need ur help for How to write the source code for downloading a file in ASP.NET 2005 using a combobox... i.e suppose i have five files in my website and i want to download any one of them ... so i will use combobox to select the filename to be downloaded and then click on the download button to download it.. so kindly provide me the source for downloading a selectedfile using combobox in ASP.NET 2005........
0
9703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10555
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10300
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9127
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5503
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4277
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2974
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.