Results 1 to 13 of 13
  1. #1
    Join Date
    Oct 2004
    Posts
    29

    Unanswered: Hide Field/Commands using macro

    I am using a macro that opens a form.
    When the form opens I want certian fields or Commands to be hidden.

    This is what I am trying Forms![FormName]![FieldName].[Visable]=False
    I have tried it in the condition that runs the Open Form Command and also in the Where Condition that runs in the Open Form action.
    Right now when it runs it hides the whole form.

    Am I missing something on the form thats opening or in the macro? I figure I'm putting the hide expression in the wrong place.

  2. #2
    Join Date
    Apr 2004
    Location
    Kingsland, Georgia
    Posts
    231
    how about "Visible" vs. "Visable?"

  3. #3
    Join Date
    Oct 2004
    Posts
    29
    It's Visible in the macro ... Sorry
    The Visable in the post was a typo
    Last edited by chrisn6104; 11-01-04 at 15:38.

  4. #4
    Join Date
    Apr 2004
    Location
    Kingsland, Georgia
    Posts
    231
    I don't really think you can do that through a macro. macros seem to carry out actions moreso than set properties of form controls. Are you wanting to use a macro vs. code because you're unfamiliar with coding? if so, we can help you out.

  5. #5
    Join Date
    Oct 2004
    Posts
    29
    I am not familiar with most VB code. I do most everything with macros. I use VB for some things but not much. Mostly for things like onCurrent to set a combo box to be the same as a field in a record.

    Although I can convert my macro to VB and add in the code to make the command buttons visible or invis. I did try some code in VB this way from what I found here but still didnt get it right. Everything I tried made the whole form either vis or invis in VB or the maco. I could never get it to effect just the one command button or field.

    I would gladly accept any help you have to give

  6. #6
    Join Date
    Apr 2004
    Location
    Kingsland, Georgia
    Posts
    231
    okay, going off of what you asked in the first post, you want to make some buttons or textboxes invisible when the form loads. open your form in deisgn view, then press Alt+F11 to open the code window. first thing to do is type "Option Explicit" underneath the words "Option Compare Database"
    In the code window, right underneath the toolbar (on my system), there are two combo boxes, the left one for object and the right for procedure. select "Form" from the left one, and select "Load" from the right one. This is the block that is run when the form is loaded into memory.
    If you want a button named cmdSave to be invisible, put
    Code:
    Me.cmdSave.Visible = False
    "Me" means the form, "cmdSave" is the button object, and "Visible" is the property.
    You'd do the same thing for a textbox named fldName or whatever it's named.
    Code:
    Me.fldName.Visible = True
    If you run into problems, just reply or post another message (I leave work in 25 minutes). There are a lot of really helpful people here.

  7. #7
    Join Date
    Oct 2004
    Posts
    29
    I didnt try what you put down yet. I'll test it here in a sec.
    But the only problem I see with it is the code is on the form itself.
    I want to use the form to fullfill more then one purpose.
    I want to be able to use the same from from diffrent command buttons on seperate forms.

    I have Form #1
    #2
    #3

    From form #2 and #3 I want to access form #1. So I open from #1 using #2 and it shows all the fields and a set of command buttons. But if I want to open form #1 using #3 I want #1 to either use diffrent command buttons with diffrent commands or not view all the fields.

    Wouldnt the code need to be on the command button on forms #2 and #3?

    It's also possible I'm looking in the wrong direction to accomplish this in the first place.
    Right now it's messy and I figure there has to be a better way.
    Right now I have form #1 and a form #1a
    from form #2 you get #1 from form #3 you get 1a. I do it this way now even if all I want is for one command button to say something diffrent or redirect to a diffrent form. If I can make diffrent command buttons show up when accessed from diffrent forms I wouldnt need a form #1a.
    Last edited by chrisn6104; 11-01-04 at 16:54.

  8. #8
    Join Date
    Apr 2004
    Location
    Kingsland, Georgia
    Posts
    231
    okay...i see. so forms 2 and 3 both open 1, right? let's say forms 2 & 3 both have a button called cmdOpen that open form 1. if 1 is called by form 2, then two buttons (buttons a & b) are visible. if 1 is called by 3, only button a is visible.
    in the cmdOpen_Click() event on Form 3, put:
    Code:
    dim frm as Form
       'opens form 1 in normal mode
       DoCmd.OpenForm "Form1", acNormal
     
       Set frm = [Forms]!Form1
        
       frm.cmdButtonB.Visible = False
    
       'if you wanted to close the current form
       DoCmd.Close acForm, "Form3", acSaveNo
    i think that'd work for you. let me know. have a great day

  9. #9
    Join Date
    Oct 2004
    Posts
    29
    Nice thanks.

    I can see whats going on I might even be able to run that in a macro. If not I'll run it like you put it down there. But thats exactly what I was looking for.
    I should be able to get in and write that sometime today.

    Thanks for the info

  10. #10
    Join Date
    Oct 2004
    Posts
    29
    So now I have another problem since I dont know VB.

    Your code works great to hide one cmdButton.
    But now what if I want to hide more then one and make others visible?

    If I write:

    dim frm as Form
    'opens form 1 in normal mode
    DoCmd.OpenForm "Form1", acNormal

    Set frm = [Forms]!Form1

    frm.cmdButtonB.Visible = False
    frm.cmdButtonC.Visible = False

    'if you wanted to close the current form
    DoCmd.Close acForm, "Form3", acSaveNo

    I get an error on the cmdButtonC line.
    I may need to make several buttons visible while several others are invis.

  11. #11
    Join Date
    Dec 2003
    Location
    Dallas, TX
    Posts
    1,004
    Quote Originally Posted by chrisn6104
    Nice thanks.

    I can see whats going on I might even be able to run that in a macro. If not I'll run it like you put it down there. But thats exactly what I was looking for.
    I should be able to get in and write that sometime today.

    Thanks for the info
    Hey Chrisn6104,

    I just wanted to say that you really should practice more on learning VBA code because Uncle Bill is playing around taking out the Macros in later versions of Access. How I learned as much as I have (and not a pro yet) was to create the Macro, then used the Convert Macro to Code wizard and learn what the code was. It is not extremely hard for basic stuff, but the more you use it the better it gets. Myself, still learning everyday in the forum and in my books. Besides, Code is much more powerful and flexible than Macros. Also, if you ever want to pull out parts of your program to move, then you have to find ALL the macros associated with the forms/reports and what have you. With the code...the code associated with forms and reports stays with them and any other modules you can easily take along. Just a tip from an up and coming Access user.

    have a nice one,
    Bud

  12. #12
    Join Date
    Oct 2004
    Posts
    29
    Yeah I think I'm going to work on learning VB

    But anyway I did the macro for this and it works.

    If anyone wants to know its the:

    (Set Value) action for the command button that opens the form just like writing the code in VB on the command button.

    The Item Set Is: Forms![FormName]![Field/CmdName].Visible
    The Expression Set Is: Yes/No or True/False

    Easy as that

    I originaly tried using the set value action I just had the Item and Expression wrong.

  13. #13
    Join Date
    Dec 2003
    Location
    Dallas, TX
    Posts
    1,004
    congrats chrisn6104,

    Nice to hear you got your problem resolved. Now, just convert that macro to code with the wizard and see just how it does it. For that particular macro, the code won't even be that long. Just one good way to learn, as that's helped me a lot. Love VBA now instead of macros. Matter of fact I haven't used not one macro in over a year now since I've been learning. And there are many advanced users here to help you along the way as I have also been helped a lot, even now.

    have a great day
    Bud

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •