473,406 Members | 2,843 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,406 software developers and data experts.

Updating combo box with data for two fields

I am looking to update a bank table using a combo box with 2 details: Bank Name and Sort Code.

I currently have a concatenated combo box, but am I able to add new information such as BankName : BankSortCode on update with a separator such as " : " to identify the 2 separate identities, and write this information back to the Bank table?

Any help on this would be greatly appreciated.

Many thanks

Tim
Dec 14 '10 #1

✓ answered by mshmyob

Just remove the Bank.BankID column and you should be OK.

cheers,

12 2790
Tim,

You can refer to multiple fields within a combo box named cbMyComboBox using cbMyComboBox.Column(0) [first field], cbMyComboBox.Column(1) [second field], etc.
Dec 14 '10 #2
Hi Steve

Thanks for this, but not 100% sure how to implement this. At present, I am just trying to put a separator in, as I do not want 2 columns in my combo box, just the one.

At present, my code is
Expand|Select|Wrap|Line Numbers
  1. Private Sub cboBank_NotInList(NewBank As String, NewSortCode As String, strSeparator As Variant, Response As Integer)
  2. Dim mbxResponse As VbMsgBoxResult
  3. Dim strSQL As String
  4.  
  5.  
  6. mbxResponse = MsgBox("Are you sure you want to add " & NewBank & strSeparator & NewSortCode & _
  7. "as a new Bank?", vbQuestion + vbYesNo)
  8.  
  9. If mbxResponse = vbYes Then
  10.  
  11.     strSQL = "INSERT INTO Bank([BankName]) " & _
  12.     "VALUES('" & NewBank & "');"
  13.     strSQL = "INSERT INTO Bank([BankSortCode]) " & _
  14.     "VALUES('" & NewSortCode & "');"
  15.     Call DoCmd.SetWarnings(False)
  16.     Call DoCmd.RunSQL(strSQL)
  17.     Call DoCmd.RunSQL(strSQL1)
  18.     Call MsgBox( _
  19.     "The new bank information has been added to the database.", vbInformation)
  20.  
  21.     Response = acDataErrAdded
  22.  
  23. Else
  24.     Response = acDataErrDisplay
  25.  
  26. End If
  27.  
  28. End Sub
  29.  
I am new to this as well, as you will probably have guessed, so any help is much appreciated!

Thanks a lot

Tim
Dec 14 '10 #3
Tim, I'm getting lost on what you are trying to accomplish. If I can help I'll need a bigger picture. What does your Bank table look like (fields in it) and what are you trying to allow the user to do?

Steve
Dec 14 '10 #4
mshmyob
904 Expert 512MB
This does not make sense.

You have created two seperate SQL Insert queries but the 2nd one overwrites the first.

You then reference strSQL1 later but there is no query for it.

If your second SQL Insert query is supposed to be strSQL1 instead of strSQL it will still not make sense because you are then trying to insert 2 seperate records with different field values and ignore other fields.

Like Steve says you need to give us a better picture of what you are trying to accomplish.

cheers,
Dec 14 '10 #5
Thank you for coming back to me about this, and sorry for the delay in replying.

As an overview, I am trying to produce a combo box where, if the required value is not present, I can type it in.

At present, I have a combo box that has Bank Name and Bank Sort Code in a single concatenated field. This contains something like the following:-

HSBC 400000
NatWest 600000
RBS 160000

I would like my users to be able to add records by typing the following:-

HSBC;400500

which would then put HSBC into the Bank Name field in my table Bank, and would put 400500 into the Bank Sort Code field in the table Bank, and would then update the combo box to show this value.

I am trying not to open a form to do this, but to use a separator to split the 2 elements of the information that is input into the 2 different fields in the table.

I need to have the sortcode separate from the Bank Name, but it is necessary to have both pieces of information in there. I am happy to hear or any other ways that I can achieve this, and once again, thank you for your assistance.

Cheers

Tim
Dec 15 '10 #6
mshmyob
904 Expert 512MB
If I understand you correctly you can try code something like so in the afterupdate event of your combo box:

Expand|Select|Wrap|Line Numbers
  1. ' check if the entry in the combo box has a ";" character
  2. If InStr(Me.YourComboBox.Value, ";") Then
  3.         Dim aStrInsert
  4.         Dim strSQL As String
  5.         'split the combo box value into 2 values using the ";" as the seperator
  6.         aStrInsert = Split(Me.YourComboBox.Value, ";", 2)
  7.         ' insert a new record with the 2 split values from the combo box
  8.         strSQL = "INSERT INTO tblBank (BankName, BankSort) VALUES "
  9.         strSQL = strSQL & "('" & aStrInsert(0) & "'," & aStrInsert(1) & ");"
  10.         DoCmd.RunSQL strSQL
  11.         Me.YourComboBox.Requery
  12.     End If
  13.  
This assumes that no ";" characters are allowed in either your BankName or BankOrder fields.

Your Combo box "Limit to List" property is set to "No"
Assumes you have an autonumber Primary key in the Bank table.

Assumes the end user put the bank name and bank order in the correct order in the combo box ie: Bank Name first, bank order second. (you really should do some kind of error checking for this)

Change your control names, field names, table names accordingly.

cheers,
Dec 15 '10 #7
Many thanks for this, looks really good. Only problem that I have is that my combo box is bound to my primary key value, which is hidden, and as such I cannot change the Limit to List property to "No", unless I unhide the primary key (which is an autonumber), and then the combo box doesn't give me the values that I want displayed!

I think I may look at getting a form to load to update the information, unless you have any other suggestions? Thanks for all of your help, it is really appreciated.

Kind regards

Tim
Dec 16 '10 #8
mshmyob
904 Expert 512MB
What do you mean it does not give you what you want. All you need to do is create a proper query for the Row Source of the combo box.

If you give more details I may be able to create it for you.

But I will say that the way you want to do it with just the combo box is not the ideal way to go. Normally you would create a proper form with proper value checking and such to ensure data entegrity.

cheers,
Dec 16 '10 #9
Thanks Mshmyob

I think that I will look at the proper form, to ensure that the data I capture is correct.

For your info, the Query that I have in the Row Source at present is:-

SELECT Bank.BankID, Bank.BankName, Bank.BankSortCode FROM Bank ORDER BY Bank.BankName;

Thanks for all your help

Tim
Dec 16 '10 #10
mshmyob
904 Expert 512MB
Just remove the Bank.BankID column and you should be OK.

cheers,
Dec 16 '10 #11
Thanks mshmyob

All sorted and really appreciate your help.

Cheers

Tim
Dec 17 '10 #12
mshmyob
904 Expert 512MB
You're welcome. Good luck with the rest of your project.

cheers,
Dec 17 '10 #13

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

Similar topics

6
by: Prakash Wadhwani | last post by:
In a small Contacts Database, I have 6 Boolean(Yes/No) Fields so that 6 individuals in the company can maintain their own private mailing list. The names of the fields are as follows: Commander...
0
by: David Lao | last post by:
Hi All, I need a way to extract Data value from the Outlook form when the new mails arrive. The data fields are provided. Thanks. David
13
by: MLH | last post by:
I have a number of reports that are essentially black 'n white prepared forms (picture an IRS form 1040). The data fields are overlaid onto the report fields in the correct positions and I would...
2
by: Java script Dude | last post by:
Hi, I basically need to write a script that will make calls to a DLL and parse the return result for API calls that consist of several data fields in the input and output parameters. Is...
1
by: pconrad | last post by:
I've got a syslog server posting to MS SQL. It works great as far as posting all the data. However, it puts all the useful information into one big text field called message. How can I parse that...
0
by: ASMJ | last post by:
Hi, I have a web page with some data fields contained in the panel and a grid view below it. The data fields are not placed in the position in which they are designed when I run the appln. After a...
13
by: wavbuser | last post by:
Is there a simple way, without setting up a module, to get certain data fields to carry over to a new record as well in MS Access 2003. I've tried alot of modifications to the "default value" but...
0
by: sijugeo | last post by:
Hi, I Have a MS word template field which have certain data fields. I want to populate the data fields using the data retrived from SQL db. How can I do this? Thanks in advance Siju george
2
by: boss1 | last post by:
hi everyone, i m having a problem with my php update code. i have 7 text fields in a webpage. i have written a code for updating multiple fields in database and it's working properly.but the...
8
by: datsandgirl | last post by:
First of all, please let me apologize in advance for my lack of technical knowledge and proper terminology skills when it comes to databases. I have never taken any classes, but have only felt my...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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,...
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
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.