473,480 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to assign values in combo box

40 New Member
Hi,
I am new to access so please bear my question.
In a form, I have a combo box(combo1) that store values in field(remarks1) in a table.The values in combo box are:
SL
ST
DI
SL + ST
SL + DI
These all values are being saved in remarks1 quiet easily.
I have more fields in the table:
SL1
ST1
DT1
SLST1
SLDI1
I want when I selet SL from combo1 it saves SL in remarks1 and save "1" as well in SL1 field.I want to have same result with all five combo1 values
Please assist me.
Nov 1 '14 #1
3 1496
jimatqsi
1,271 Recognized Expert Top Contributor
Combo boxes have an After Update event. In the After Update event of combo1 you can put some VBA code to update any other fields you want. You'll put something like
Expand|Select|Wrap|Line Numbers
  1. me.SL1 = 1
if it's a numeric 1 or
Expand|Select|Wrap|Line Numbers
  1. me.SL1="1"
if it's an alpha.
Of course you'll have to put that in a select case or if/then mechanism to make sure you're setting the right value in SL1. Like this, for instance:
Expand|Select|Wrap|Line Numbers
  1. Select case me.combo1
  2.    case "SL"
  3.         me.SL1=1
  4.    case "ST"
  5.         me.SL1=???
  6.    case "DI"
  7.    case "SL+ST"
  8.    case "SL+DI"
  9. end select
  10.  
I'm not exactly sure what you mean by "I want to have same result with all five combo1 values" but if you get the above I suspect you can expand on that easily.

You might consider making combo1 a 2-column combo box. You could have the 2nd column invisible (columnwidths=1;0; assuming width=1 for column 1 is okay). In the second column you could have the value that matches the first column. In that case, your VBA code could be
Expand|Select|Wrap|Line Numbers
  1. me.SL1=me.combo1.column(1)
Column(1) refers to the 2nd column, not the first.

Hope that helps.
Nov 1 '14 #2
irslan rafique
40 New Member
Thanks a lot for putting me on right track.
I am using this code now:
Expand|Select|Wrap|Line Numbers
  1. Select Case Me.Combo1043
  2.    Case "Staging"
  3.         Me.Staging1 = "1"
  4.    Case "Diversion"
  5.         Me.Diversion1 = "1"
  6.  
  7. End Select
But one problem.
If i select Staging and suppose the actual value is diversion so I will select diversion in the combo box so in result it passes "1" in both related fields (Staging1 & Diversion1)
Need your more help please.
Nov 1 '14 #3
jforbes
1,107 Recognized Expert Top Contributor
I'm not exactly sure what you are attempting to do, but I'm guessing that you want all the fields set to nothing except the fields you are setting to one. If this is true, you can use the following:
Expand|Select|Wrap|Line Numbers
  1. Select Case Me.Combo1043
  2.     Case "Staging"
  3.          Me.Staging1 = "1"
  4.          Me.Diversion1 = "" 
  5.     Case "Diversion"
  6.          Me.Staging1 = ""
  7.          Me.Diversion1 = "1" 
  8.  End Select
If you are looking to put a "0" in that field instead, use:
Expand|Select|Wrap|Line Numbers
  1. Select Case Me.Combo1043
  2.     Case "Staging"
  3.          Me.Staging1 = "1"
  4.          Me.Diversion1 = "0" 
  5.     Case "Diversion"
  6.          Me.Staging1 = "0"
  7.          Me.Diversion1 = "1" 
  8.  End Select
Nov 3 '14 #4

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

Similar topics

6
1720
by: Buddy Ackerman | last post by:
I created a simple class: Public Class MyTestClass Public Test() As String End Class I tried to assign some values to the array Test() and display them like this:
2
1830
by: MLH | last post by:
Gentlemen: I have declared an array Dim MyTables(14) AS Long Now I want to assign values for MyTables(0) - MyTables(14) equal to the number of records in each table. Catch, I want the code...
7
21915
by: Paul via AccessMonster.com | last post by:
I have a report with some Unbound text boxes. I want to shows the values in these text boxes from my VBA code. How can I assign the valuse thru code ? Pls help me. -- Message posted via...
2
7197
by: gjtired | last post by:
Currently I am retrieving values from a dataset and assigning the values to a textbox. I then assign the value from the textbox to a variable. I don't need the values in the textbox at all. I'm...
2
2957
by: dBNovice | last post by:
Hi all! I have 3 separate forms: Tasks, Subtasks, and Elements. All 3 is related by TaskId and Subtasks and Elements are related by SubtaskID. In the DB after I add a task, I want to be able to...
6
2244
by: david | last post by:
I try to use "for" loop to retrieve and assign values in web form. The code is in the following. But it can not be compiled. What I want to do is: txtQ1.Text =...
8
1833
by: fanoftvb | last post by:
hi, is it possible to assign values to button? I will not need to enter any values and when i click on the button, the values on the datagrid and database will automatically change. Is there anyway...
1
2698
by: NewHeights | last post by:
Excel 2007- I have a survey that uses radio buttons (3 choices each answer) to select the answer.? My trouble starts with assigning values to the answers (Answer 1 is 0, Answer 2 is 1, Answer 3 is...
1
1061
by: gourik | last post by:
Can we assign values for symbolic constants in enumerations where value assigned for Is it possible in c#? If not then please give me the reason? enum student { UG=10; PG=100; }
0
7041
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
6908
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
7044
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,...
1
6739
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...
1
4779
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
2995
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...
0
1300
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 ...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
181
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...

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.