Results 1 to 10 of 10
  1. #1
    DLParker is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2011
    Posts
    5

    Access 2010 first macro - errors

    I'm having trouble setting up my first macro.



    I'm trying to create a form where certain controls are displayed or hidden based on a value in another control. Access's help file suggested I should use a macro if possible. After scanning through a few books and web pages I thought I had the right structure:

    Users will select one of the following values: "LOCAL"; "MORE"; "OCLC"; "UNFILLED" from a combo box named LoanType. The control LocalLender has its Visible property set at No to start with. I want it to change to Yes when LOCAL is selected from the list. Both fields are text fields.

    I clicked in the On Change property for this combo box and chose the Macro Builder. This is the expression:

    IF [Forms]![ILL Requests Form]![LoanType]="LOCAL" Then

    SetProperty

    Control Name [Forms]![ILL Requests Form]![LocalLender]

    Property Visible

    Value Yes

    When I try to run this macro, Access gives me a Type Mismatch error. Once I get this part working, I want to make other controls visible when other values are chosen from the LoanType box. I would appreciate any help you can give!

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    What is the RowSource of the combobox? I suspect it is multi-column and value is actually a record ID, not the text descripter.

    I use VBA. I would select [Event Procedure] in the event property, double click the ellipses (...), this will put you in the procedure. Then code would be like:

    Select Case Me.LoanType
    Case 1
    Me.LocalLender.Visible
    Case 2
    ...
    End Select
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    DLParker is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2011
    Posts
    5
    The Row Source Type for the combo box is a Value List and the Row Source itself is "LOCAL";"MORE";"OCLC";"UNFILLED"

    I'm very new to VBA. When you suggest the solution

    Select Case Me.LoanType
    Case 1
    Me.LocalLender.Visible
    Case 2
    ...
    End Select

    can you give me an example of how to write a "case 1" expression? would that line simply read

    "LOCAL"

    or

    = "LOCAL" or what?

    Thanks!

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    So the combobox is not multi-column and LoanType field is text datatype? Don't understand why the macro errors.

    Put in place of 1, 2 whatever value you want to match, no equal sign required, like: Case "Local".
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    DLParker is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2011
    Posts
    5
    Quote Originally Posted by June7 View Post
    So the combobox is not multi-column and LoanType field is text datatype? Don't understand why the macro errors.
    Yeah, me either.

    Okay, here's what I have now:

    Private Sub RequestSource_AfterUpdate()
    Select Case Me.LoanType
    Case "LOCAL"
    Me.LocalLender.Visible
    Case "OCLC"
    Me.ILLNo.Visible
    Case "MORE"
    Me.MOREno.Visible
    End Select
    End Sub

    and I get a "Compile Error Invalid Use of Property" with the .Visible of Me.LocalLender.Visible highlighted. Any further insight? Is there a problem placing this code in the After Update property? Or is the Visible property not set-able this way? Thanks again.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    This is possible. I have done it. Is LocalLender the name of a textbox or combobox or listbox on the form? I always give data controls a name different from the field they are bound to, like: txtLocalLender or cbxLocalLender or lbxLocalLender.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    DLParker is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2011
    Posts
    5
    Many, many thanks for the good advice. I have a working event procedure! This is what I ended up with:

    Select Case Me.cbxLoanType
    Case "LOCAL"
    Me.cbxLocalLender.Visible = True
    Me.lblLocalLender.Visible = True
    Case "MORE"
    Me.cbxMORENum.Visible = True
    Me.lblMORENum.Visible = True
    Case "OCLC"
    Me.cbxOCLCNum.Visible = True
    Me.lblOCLCnum.Visible = True
    End Select

    Now my boxes and their labels appear only when needed. And you're right: giving the various controls names that distinguish them from their bound fields, similarly-named objects, etc., helps keep them straight.

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    If the label control is associated with data control, no need for separate code, it will do what the data control does.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    DLParker is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2011
    Posts
    5
    For whatever weird reason, my labels stay visible unless I specifically hide them. But otherwise everything works!

  10. #10
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    I just just tested VBA that sets textbox not Visible and its associated label also becomes not visible. Select the data control, if the label is associated it will also be selected and move with the control. You have a solution, so this is just a matter of curiosity if you want to pursue.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Access 2010 Macro Help
    By RayMilhon in forum Access
    Replies: 3
    Last Post: 09-30-2011, 12:03 PM
  2. Access 2010 Macro
    By RayMilhon in forum Access
    Replies: 3
    Last Post: 09-28-2011, 11:37 AM
  3. 2007 to 2010 macro won't work
    By lmnnt in forum Programming
    Replies: 6
    Last Post: 08-10-2011, 01:55 PM
  4. Replies: 1
    Last Post: 10-15-2010, 06:09 AM
  5. Replies: 0
    Last Post: 07-13-2010, 07:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums