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

Need VBA Code to check a Yes/No box based off a Combo box selection

DJRhino1175
221 128KB
Looking for help on code to check the yes no box if a certain selection is picked from the combo box. For example if I pick "Purchased" from the combo it will put a check in the Yes/No box labeled "Purchased Component". Seems like it should be easy, but I'm having a brain fart and seem to think of how to do it.

Thanks for all the help.
Apr 3 '19 #1
11 979
twinnyfo
3,653 Expert Mod 2GB
DJ,

As usual, we ask our posters to submit their work so far. We would much prefer to troubleshoot than create.

Also, if your current procedure produces any errors, it would be helpful to know those, as well.
Apr 3 '19 #2
DJRhino1175
221 128KB
Have done code yet, as I'm not sure where to start other than in the after update on the form; after that not sure what to do.
Apr 3 '19 #3
twinnyfo
3,653 Expert Mod 2GB
Well then....

Without getting into specifics, which would be impossible based upon the information given, you would have a procedure in the AfterUpdate event of the Combo box. Check the value of the combo box and based upon its value, set the value of the other Check boxes.

I can't give you more, because I don't know the content of your combo box, nor the specific names of your controls.
Apr 3 '19 #4
DJRhino1175
221 128KB
Combo Name=RejectAreaCodeID
Yes/No Box Name=Purchased Component?
Form record source Name=QRY-NewTag

Combo box has around 5 entries in it, but only need the code to work when "Purchased"(ID Number 11) is pick from the dropdown.
Apr 3 '19 #5
twinnyfo
3,653 Expert Mod 2GB
DJ - the implication here is that you will try to implement the instructions above into a solution that might work. I know you've been around here long enough to know the general procedures.

We typically ask the posters to try to build their own solutions and then we will gladly troubleshoot.
Apr 3 '19 #6
DJRhino1175
221 128KB
Expand|Select|Wrap|Line Numbers
  1. If [REJECT AREA]![Reject Code Name] = "Purchased" Then
  2.  
  3.         [Reject tags]![Purchased Component?] = True
  4.  
  5.     End If
I tried this and got an error I have never seen before when debugging it.

Compile error:

Qualifier must be Collection

Highlights this part of the code
Expand|Select|Wrap|Line Numbers
  1. ![Purchased Component?] =
Apr 4 '19 #7
twinnyfo
3,653 Expert Mod 2GB
So..................

Let's start with some good advice, based upon years of experience, and offered to grant yourself and otherss some sanity when reviewing your code.

Just based off your code, I have no idea what [REJECT AREA], [Reject Code Name], [Reject tags] and [Purchased Component?] represent. This is the first challenge with trying to figure out your code. We'll come back to this in a moment.

In a previous post, you stated:
Combo Name=RejectAreaCodeID
Yes/No Box Name=Purchased Component?
Form record source Name=QRY-NewTag
This is not helpful for either sets of information you have provided, as the only consistent element between the two is Purchased Component?, which apparently is a Check Box?

So, here is the advice part (you will hear me telling all folks on this forum the same thing): find a good naming convention for your database objects and use it for every object in your database. At least you have made an attempt at that for your Query Name.

For example, I have no idea what the name of your Form is. But if you had a form named frmComponents, then you and I can automatically make some general assumptions about things without needing additional information. First, we know that we are talking about a Form object--this is helpful, because we know what forms do and how they work. Second, we also have an idea that this Form deals with Components. Now, greater detail might be required to help us understand what aspect of Components this Form deals with, but it gets us headed in the right direction before we even start troubleshooting.

So, here is brief naming convention that might get you started:

frm - Forms
rpt - Reports
cbo - Combo Box
txt - Text Box
chk - Check Box
lbl - Label
qry - Query
tbl - Table
cmd - Command Button

If you search for Database Naming Conventions, you will find plenty to choose from. Just pick one and stick with it. It will save you (and especially others) many headaches.

Second, try (at all costs) to avoid spaces and special characters in your naming convention. Having a Question mark may be an acceptable character in MS Access's system, but it is not wise, as the question mark may also be a wildcard. This can cause problems down the road. Avoiding spaces makes it easier to refer to things in VBA (especially when working with Field Names within recordsets).

Now, based upon the code you provided, it is literally impossible for me to troubleshoot.

However, I ask you to make some changes to your naming convention and then update your code to reflect those naming changes and repost those changes. I'll be glad to take a look once things make more sense.

Thanks.
Apr 4 '19 #8
NeoPa
32,556 Expert Mod 16PB
What I'm observing here is that DJ seems mostly happy to let Twinny do all the heavy lifting for the work in his own project. That's a real problem and I will continue to observe.
@DJ.
Please. Prove me wrong.
Apr 4 '19 #9
DJRhino1175
221 128KB
So after a little more research and walking away from the project I got it figured out.

Expand|Select|Wrap|Line Numbers
  1. Private Sub REJECT_CODE_NAME_AfterUpdate()
  2.  
  3.      If Me.[REJECT AREA].Value = "Purchased" Then
  4.  
  5.         Me.[Purchased Component?].Value = True
  6.  
  7.         Else
  8.  
  9.         Me.[Purchased Component?].Value = False
  10.  
  11.     End If
  12.  
  13. End Sub
You have now been proved wrong @NeoPa - All I was looking for was for direction, not someone to do the heavy lifting.

And thank you Twinnyfo for your naming strategy. This was an older Database that I made before this group got me fixed on how to make them correctly. I am in the process or redoing this one as an upgrade from all of the stuff I learned here and other research I have been doing.

I the newer version it worked right away, but when I tried it on the older version is where I had the problem, but now have it.

I'm only updating the old one as a stop gap till I get the newer version completed to my liking.
Apr 4 '19 #10
twinnyfo
3,653 Expert Mod 2GB
One of NeoPa's tricks:

Expand|Select|Wrap|Line Numbers
  1. Private Sub REJECT_CODE_NAME_AfterUpdate()
  2.     Me.[Purchased Component?] = _
  3.         (Me.[REJECT AREA] = "Purchased")
  4. End Sub
Also, no need to use the .Value Property, as it is the default.
Apr 4 '19 #11
NeoPa
32,556 Expert Mod 16PB
DJRhino:
You have now been proved wrong @NeoPa - All I was looking for was for direction, not someone to do the heavy lifting.
It's a step in the right direction. The data doesn't lie. Your approach in this thread was to allow Twinny to do all the hard work as evidenced by the various posts. If you don't understand that then the future doesn't look very bright.

If your new approach shows consistently then I'll be happy to accept you've turned over a new leaf.
Apr 4 '19 #12

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

Similar topics

2
by: sam | last post by:
For Example, If I delete two times like the below code, the program will behave differently. is this correct? As C++ FAQ the delete checks where or not f1 has memory. How can the following program...
1
by: thegame | last post by:
Filling One DataGrid Based on Selection from Another DataGrid - Both in Separate User Controls Hello, I have an interesting dilemma. I have an ASPX page with two user controls (two ASCXs). ...
2
by: Ponnurangam | last post by:
Hi, I need to check whether a file named flower exists with different extensions. I know only file name. I don't the the extension(may be .bmp, .ipg, or ..gif). And if there are files with...
0
by: ROO | last post by:
Hi Everyone, I have a database table that have 4 field( C1, C2, M1, M2) on my form i have two combo box ComboC and ComboM C1 C2 M1 M2 1 ...
2
by: akunuri.swapna | last post by:
Hi All - I have a checkedListBox in my form. I am adding items to it at run time. However I also need to check the items depending on a condition. I have tried a lot but cant get the added item to...
3
by: dhutton | last post by:
SQL Server 2000 How do you write your query to check for blank (empty) cells? Need to check 3 columns. ColumnA, ColumnB and ColumnC. I need to grab the data in ColumnA ONLY if ColumnB and...
6
by: Jack | last post by:
Hi, I am still new to .NET so, i'm sorry if my question is a bit too simple :-) I would like to know what is the "best-practice-way" of sending email from asp.net (VbScript). I want to make a...
3
by: JoeP | last post by:
Hi All, Need to check if the propery of an object exits. oMyObject.Message In some cases the Message property may not exists. I know the GetType() can do it. How would you check it?
4
by: dekk | last post by:
I am trying to populate a text field from the combo selection. I have the following update event in the combo box Private Sub cboContract_AfterUpdate() Me!txtDesc = Me!cboContract.Column(1)...
0
by: mahee | last post by:
i want to check the values in row which is in Datareader. i have a table called Annual and i retrieved 1 row from that table. I stored row values into an array.now i need to check the values in the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.