Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Show/Hide fields in a form 2

Status
Not open for further replies.

aaabuhalime

Instructor
Nov 22, 2012
67
US
Hi again,
This is my last question here, I have created a form that holds three fields ID, Name1,address1, two combo boxes(28,30), the field Name1 is a combobox, that holds different names, what I want to do is if i select the name I want one of the two boxes to disappear, or to hide, for example if I select, the name Ed, I want combobox 28 to disappear, This is what I am using, I tried invisible, I got an error, data Not Found. Any help will be appreciated.

Thanks


Private Sub Combo28_AfterUpdate()
Me.Combo28.Visible = (Me.Name1 = "Ahmed")
End Sub

Private Sub Form_Current()
Me.Combo28.Visible = (Me.Name1 = "Ahmed")
End Sub
 
Hi aaabuhalime,
Just a couple of points to start with:

[ul][li]Please confirm that the name of the Name1 control is, in fact, "Name1". :) Just given the error, it looks like it's having trouble finding a control called, "Name1" on your form. (To find/edit the name of the control, select the control in design view, go to properties, and then find "Name" in the "Other" tab).

[/li][li]Null values may cause issues with this code. You should probably change:
Code:
(Me.Name1 = "Ahmed")
..to:
Code:
(Nz(Me.Name1,"") = "Ahmed")

[/li][li]This isn't really related, it's just a side note... but I recommend renaming Combo28 to something more descriptive, since it pops up in the code (in fact, anytime you create a control in the form, I recommend naming it with something descriptive. This will also make it easier to find if your form grows over time).
[/li][/ul]

Otherwise, I can't see any issues with your code. Please let me know if this does or does not help. :)

Katie
 
Thank you very much Katerine, the code worked fine, I will try your suggestion, but I would like to ask another question, how the code should look like if I want to hide more than one field,or should I go to each field and do the same thing(each combobox), also If I want the combobox to show if I select two names ,for example :

Private Sub Combo28_AfterUpdate()
Me.Combo28.Visible = (Me.Name1 = "Ahmed")
or
Me.Combo28.Visible = (Me.Name1 = "XY")
End Sub

Is this a right Syntax?? and can I use the same code with the disable option, if I want to disable the fields.

Many thanks in advance:)
 
No, that wouldn't work. You need to have one assignment statement, with multiple conditions, not multiple assignment statements.

Try one of the following (whichever you prefer):
Code:
Combo28.Visible = (Me.Name1 = "Ahmed" Or Me.Name1 = "XY")

Code:
Select Case Me.Name1
Case "Ahmed", "XY"
   Combo28.Visible = True
Case Else
   Combo28.Visible = False
End Select


Katie
 
Dear Katerine,
I have one more question, I have a from that is created from a query X and the report created from query Y, both queries having almost the same fields and both created from the same table,what I did I created a query that combines the two, and made it the source for the query and report, what I have been trying to do, when I enter the Participant ID and the Assessment Date on the form and click on the button , the report should open with the specific records based on the ID and Date, I have used the following code,

Private Sub Command108_Click()


Dim strDocName As String
Dim strWhere As String
strDocName = "rptXY"
strWhere = "[ParticipantID] = """ & Me.[ParticipantID] & """ And [AssesmentDate]=#" & Me.AssessmentDate & "#"
DoCmd.OpenReport strDocName, acPreview, , strWhere


End Sub

Now what happens is when I enter the Id and the Date, and click the button to open the report , there is MSG box displayed asking me to enter the date, I don't know why, when I enter the date doesn't show the the exact record , it brings all the records fro this ID I have to navigate using arrows to the right record. Can you please help me with this?

Thanks
 
1) please learn how to use TGML to format you messages for easier reading
2) your code assumes ParticipantID is text/string. Is this the case?
3) what is the exact MSG box text? Is it asking for AssesmentDate? If so, it's probably your spelling of the field name:

Code:
Private Sub Command108_Click()
  Dim strDocName As String
  Dim strWhere As String
  strDocName = "rptXY"
  strWhere = "[ParticipantID] = """ & Me.[ParticipantID] & """ And [Asses[COLOR=#CC0000][b]s[/b][/color]mentDate]=#" & Me.AssessmentDate & "#"
  DoCmd.OpenReport strDocName, acPreview, , strWhere
End Sub

Duane
Hook'D on Access
MS Access MVP
 
Dear dhookom,
I do really apologize for not using TGML, I checked the TGML option but it is not, I promise I will, and thank you very much for your help, finally it worked. Now for the future to use TGML format all what I need to do is click on the code tab before "Preview Tab" to write my code? is that right , also I would like to know if you suggest any book that wold help and teach me the VBA tips. But I will be still asking you :)


Thanks
 
You should see a bar of formatting options immediately above the window where you type in your reply. This is to the left of the Preview and Submit Post buttons. These are very much like the formatting buttons in Word or other rich text interfaces.

Duane
Hook'D on Access
MS Access MVP
 
Thank you , but I would like to if you suggest any book/a way that wold help and teach me the vba tips.
 
Hi
I have a more detaild question about how to disable/hide a page in a navigation form based on a combobox value, in one the previous posts (Katerine) checked my code, every thing wored perfectly based on one combobox, my question how about if I want to hide the page based on two comboboxes values, for Example If I want to Hide the Invoice page/tab in the navigation form based on the SName Combobox ,and the Paid(Yes/No) Combobox, Can I use the follwing code?
Code:
Select Case Me.SName1, Me.Paid
Case "John", "Yes"
   Me.Page90.Visible = True
Case Else
   Me.Page90.Visible = False
End Select

I added a code under the second combobox, basically the same previous code with only Me.Paid, and added the code on the on current event
Code:
Select case Me.Paid
Case "John"
   Me.Page90.Visible = True
Case Else
   Me.Page90.Visible = False
End Select
, but for some reason it is not wroking, they may contradict each other,because I already have acode behind the the first combobox, and on current event as will, I want to know how to hide a page based on two comboboxes valuee. Any input/help will be appreciated.

Thanks
 
What about this ?
Code:
Select Case Trim(Me.SName1) & Me.Paid
Case "JohnYes"
   Me.Page90.Visible = True
Case Else
   Me.Page90.Visible = False
End Select

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV,
Thank you for your reply, Where this code should go behind the first combobox?, or the second combobox? also on current event I have the code from the fist combobox, how can can include or copy this code under on current event with our causing any conflict with old code.
 
Hi,
I have a question please, I am working on a multitab form called main,this form includes a subform, is there away to hide or show one pages/tabs based on the value of the subform, for example if the money collected in the subform if yes , I want one of the tab collection/page90 to disappear in the main form ? any help wil be apprecited.
Private Sub MoneyCollected_AfterUpdate()
Code:
Select Case Me.[MoneyCollected]
Case "Yes"
Me.Page90.Visible = False
Case Else
Me.Page90.Visible = False

End Select
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top