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

using combobox for value input

Knut Ole
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 3104
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,556 Expert Mod 16PB
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 Expert Mod 2GB
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=AcDataErrContinue 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
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 Expert Mod 2GB
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, 118 views)
Apr 12 '11 #6
NeoPa
32,556 Expert Mod 16PB
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
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,556 Expert Mod 16PB
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
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
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)) {...
9
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...
1
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...
1
by: luthriaajay | last post by:
Using <xsl:value-of in XSL XML file <i:Details> <i:Stra> <stra:Desc>ABC</stra.Desc>
3
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...
15
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
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
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...
1
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...
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: 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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.