I have been looking through posts on events happening based on a combo box choice but none really get at the heart of what I am trying to do.
I think this is simple but I'm a newbie so any hand holding and non-startling movements will help here. :-)
I have a form Specimen with a dropdown that displays Species by Species_Code. In the Species table I have a Yes/No field for whether or not the Species is a Fish (Yes = fish). If the user chooses a Species_Code that is a Fish I want the subform to become enabled.
Seems like this is pretty simple but I don't know VB (though I can kind of follow it when I see it written) and am not sure on which event to put this on or how to tie a field from the Species table that isn't being displayed in the dropdown to the subform. Is that confusing?
Basically --> If user chooses a Species_Code that has Fish = yes for that record then subform.visible = true.
Help!
Melissa
26 5693 ADezii 8,834
Recognized Expert Expert
I have been looking through posts on events happening based on a combo box choice but none really get at the heart of what I am trying to do.
I think this is simple but I'm a newbie so any hand holding and non-startling movements will help here. :-)
I have a form Specimen with a dropdown that displays Species by Species_Code. In the Species table I have a Yes/No field for whether or not the Species is a Fish (Yes = fish). If the user chooses a Species_Code that is a Fish I want the subform to become enabled.
Seems like this is pretty simple but I don't know VB (though I can kind of follow it when I see it written) and am not sure on which event to put this on or how to tie a field from the Species table that isn't being displayed in the dropdown to the subform. Is that confusing?
Basically --> If user chooses a Species_Code that has Fish = yes for that record then subform.visible = true.
Help!
Melissa
I would have liked a little more information but I'll make some basic assumptions such as:
__1 Your Combo Box is named cboSpeciesCode.
__2 Your Species Table contains the Fields [Fish] (Yes/No), [Species] (Text), and [Species_Code] (Long).
__3 Your Sub-Form name is subfSpecies.
__4 Make any other adjustments as needed.
__5 In the AfterUpdate() Event of cboSpeciesCode: - Private Sub cboSpeciesCode_AfterUpdate()
-
Dim intSpeciesCode As Integer, IsItAFish As Integer
-
-
intSpeciesCode = Me![cboSpeciesCode]
-
IsItAFish = DLookup("[Fish]", "Species", "[Species_Code]=" & intSpeciesCode)
-
-
If IsItAFish = -1 Then 'True - it is a fish
-
Me![subfSpecies].Visible = False
-
Else
-
End If
-
End Sub
Sorry! I should have specified these things. I made appropriate changes but Species_Code is text, not a long integer. So it seems to be getting hung up on this line: -
IsItAFish = DLookup("[Fish]", "Species", "[Species_Code]=" & intSpeciesCode)
-
What do I have to change? Also, could you explain what the line does so I know how to apply it next time?
Here is what I changed it to: - Private Sub Species_AfterUpdate()
-
Dim intSpeciesCode As Integer, IsItAFish As Integer
-
-
intSpeciesCode = Me![Species]
-
IsItAFish = DLookup("[Fish]", "Species", "[Species_Code]=" & intSpeciesCode)
-
-
If IsItAFish = -1 Then 'True - it is a fish
-
Me![subfrm_FishSpecimen].Visible = False
-
Else
-
End If
-
End Sub
Thank you!
More information:
Combo box is called "Species", Species Table has fields [Species_ID] (autonumber, PK), [Species_Code] (text), [Common_Name] (text), [Family] (text), [Genus_ID] (autonumber, FK), [Scientific_Name] (text), [Alternate_Name] (text), [Fish] (Yes/No).
Do I need to include all these in the code?
Subform name is sbfrm_FishSpeci men
Here is what I changed your suggested code to: - Private Sub Species_AfterUpdate()
-
Dim intSpeciesCode As Integer, IsItAFish As Integer
-
-
intSpeciesCode = Me![Species]
-
IsItAFish = DLookup("[Fish]", "Species", "[Species_Code]=" & intSpeciesCode)
-
-
If IsItAFish = -1 Then 'True - it is a fish
-
Me![subfrm_FishSpecimen].Visible = False
-
Else
-
End If
-
End Sub
Thank you!
Anyone know how to change this if SpeciesCode is a string? -
Private Sub Species_AfterUpdate()
-
Dim intSpeciesCode As Integer, IsItAFish As Integer
-
-
intSpeciesCode = Me![Species]
-
IsItAFish = DLookup("[Fish]", "Species", "[Species_Code]=" & intSpeciesCode)
-
-
If IsItAFish = -1 Then 'True - it is a fish
-
Me![subfrm_FishSpecimen].Visible = False
-
Else
-
End If
-
End Sub
-
Obviously Dim SpeciesCode As String but how do I change the DLookup line?
Also, why is -1 a true value? Shouldn't it be just 1?
thanks for any help!
Wow, how quickly this got buried!
Anyway, I am getting this error:
Run-time error '94':
Invalid use of Null
Here is my code now (I changed some table and form names) -
Private Sub cboSpecies_AfterUpdate()
-
Dim SpeciesCode As String, IsItAFish As Integer
-
-
SpeciesCode = Me![cboSpecies]
-
If IsNull(Me.cboSpecies) = False Then
-
IsItAFish = DLookup("[Fish]", "[tbl_Species]", "[Species_Code]= '" & Me.cboSpecies & "'")
-
End If
-
-
If IsItAFish = -1 Then 'True - it is a fish
-
Me![subfrm_FishSpecimen].Visible = False
-
Else
-
End If
-
End Sub
I have tried all sorts of things with the DLookup line and I get either the Inavlid use of Null error or a data mismatch error, no matter what I put in the criteria part of the function.
Any ideas?
thanks,
melissa
Okay I got it! Finally! I was confused on the combo box and was using the value shown (text) vs the bound source (integer).
Anyway, it works beautifully.
HOWEVER, if I change the value in the dropdown the function doesn't refire. Sort of.
So if I choose a non-fish in the dropdown the subform doesn't show. If I change the dropdown to be a fish the subform does show (hurrah!). If I change the dropdown to a non fish again the subform is still there. How do I change that?
Basically, I want the subform to show only when the user chooses a fish. If they make a mistake and go back and change it to non-fish the subform needs to disappear.
Thanks!
NeoPa 32,579
Recognized Expert Moderator MVP
Melissa,
Give me some time (maybe over the weekend) and I'll come back to you on this one. I'm just leaving work atm.
There are a number of questions in your posts and I'd like to cover them as they all seem to point to your better understanding the subject, which is a bonus for all of us here :)
NeoPa 32,579
Recognized Expert Moderator MVP
Let's try this one at a time shall we.
I'll respond to some of your points then we'll see if we can take it from there. True.
True is held as -1 because boolean fields are stored as numbers in a binary field. In a binary field, when all bits are set to one, the equivalent numeric value is -1. In an associated point, it is never a good idea to compare boolean fields.
IE. Never say If MyBoolean = True (or -1 even) Then... Always say If MyBoolean Then... instead. Lack of Response.
This can happen sometimes and is usually the result of some confusion or some expert being away for a short while. You know from personal experience that it is unusual. However, if for any reason an expert is working on your thread and his notifications become reset (there is a bug in the site currently which is being looked at) then he will not be aware of your responses I'm afraid.
Knowing ADezii as I do, I'm sure he wouldn't leave you hanging like that deliberately. The Access forum is currently so busy that hunting for non-registered threads is more than most of us can manage. It doesn't look like an orphaned thread at first glance you see.
NeoPa 32,579
Recognized Expert Moderator MVP
I'm assuming that the control [FishControl] (You need to supply the name of this control) is displayed and updated when a species is selected in the ComboBox [Species].
If so then the following should work for you : - Private Sub FishControl_AfterUpdate()
-
Me![subfrm_FishSpecimen].Visible = Me!FishControl
-
End Sub
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: CSDunn |
last post by:
Hello,
In Access ADP's that connect to SQL Server databases, any time I have
a situation where I have a combo box in a main form that looks up a
record in a subform, the subform record source has to be based on
either a View or a Table. I can almost always use a View, and it helps
to do this since I can have better control over the size of the
RecordSet of the subform.
There are times when the use of a Stored Procedure would give me...
|
by: Donna Sabol |
last post by:
I have a form (frm_MAIN_RPT) that contains a combo box (Combo6) &
subform (dbo_REQ_subform). The combo box is used to select the "cost
center" data that will be displayed in the subform. From there, I
have a button that runs a report based on which item I select in the
subform.
1. The Combo Box correctly displays the list of cost centers within
the combo box.
2. The subform, when opened separately, correctly displays the data
for the...
|
by: misscrf |
last post by:
I have this normalized database, and I don't understand why setting up
the forms is so hard for me. I have the main candidate entry form.
This is to enter in candidates who apply for a job. I have a tab
control with a page that shows if the candidate type is 1 of a few
types ( in code). Otherwise 2 pages show. 1 is for contact
information. This has an address subform and a phone subform. I can't
figure out how to show all address,...
|
by: NBruch |
last post by:
Ok let me explain what im trying to do:
i need a combo box which needs to be linked to a listbox (or combo box
doesnt matter which really) then the listbox should bring up the record
in a subform.
so you pick a name (in the combo box in the main form) then it should
bring up all the dates for which the person has a record for (in the
list box or combo box) and then once you pick a date it should bring up
the specific record you want...
|
by: MLH |
last post by:
I have a form with a subform control on it listing
records returned by a saved query named UnbilledVehicles.
I would like to put command buttons on the main form
to apply dynamic filters to the records displayed in the
subform control. Say, for instance, to list only 2004 model
cars. I'm seeking the simplest approach.
The main form is frmCreateInvoice, the subform control
is named frmCreateInvoiceSubFormCtl and the actual sub-
form is...
| |
by: Ecohouse |
last post by:
I have a main form with two subforms. The first subform has the child
link to the main form identity key.
subform1 - Master Field: SK
Child Field: TrainingMasterSK
The second subform has a master-child link to the first subform.
subform2 - Master Field: subTrainingModule.Form!TrainingModuleTopicSK
Child Field: TrainingModuleTopicSK
|
by: Rex |
last post by:
I have a main form and a subform. The main form has a combo box
control and the subform has a textfield.
What I want to do is when the main form loads it should check the
value of the combo box and if it, lets say "MZ" then the textfield in
the subform must be enabled otherwise it should be remain disabled.
This should be done without setting any explicit focus.
Any help would be greatly appreciated.
|
by: JHite |
last post by:
I am using Access 2003 on Windows XP.
This is a simple database that contains “tblStaffers” containing names of the office staffers, “tblProjects” containing names of the office projects, and “tblStatusReports” containing the “StafferID” (link to Staffer table), the “ProjectID” (link to Projects table), a “Date” field, and a “Notes” field.
There is a main form, “frmStaffEntry,” with a subform, “frmStatusReports,” for a user to...
|
by: JHite |
last post by:
I’m using Access 2003 on Windows XP.
I have a Mainform (Staff Entry) which displays an unbound combo box named ChooseStaff. The Row Source for this combo box is a SELECT of the UserIDs and Staffer Names from a table (Staffers) which contains staffers’ names and other info.
When the user actually selects a Staffer Name from the dropdown combo box, the VBA routines for the combo box’s On Enter and After Update events take care of finding and...
|
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...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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...
|
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,...
|
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...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |