Results 1 to 8 of 8
  1. #1
    cbh35711 is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Posts
    40

    Macros Not Showing

    I have this code in a module.



    Code:
    Public Sub Attach_loan()
    Obligor_id = Forms![Borrower Details]![Obligor_id].Value
    End Sub

    It doesn't show up when selecting macros in Access. Hitting Run in VBA works fine, but i can't run it automagically from access.

    Click image for larger version. 

Name:	Capture.PNG 
Views:	19 
Size:	41.6 KB 
ID:	7042

    Any idea what i'm doing wrong?

    Thanks!

    Chris

  2. #2
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    When I have code [usually a Function] in a module that I want to run from a Macro, I create a new Macro & choose the 'Run Code' option.
    That Sub is not a Macro - so I wouldn't expect it to show up in the Run Macro dialog box.
    I have never tried running a subroutine using the 'Run code' option.

    Hope this helps.

  3. #3
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    As Robeen has pointed out, a Sub is not a macro, so you won't see it in macro lists. But what are you trying to do with this sub, specifically, what is Obligor_ID? Is there more code in this Sub that you did not post? If Obligor_ID is a simple variable, then in order for it to be of any use, it would have to be declared outside of that Sub.

    Another question - where is the module that includes this sub?

    Can you post more info, please?

    John

  4. #4
    cbh35711 is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Posts
    40
    A sub seems to be a macro in Excel. It runs just like you would think. Ok i'm confused on why you would say it's not a macro. How should i declare it?

    The macro itself doesn't really matter. But obligor_id is a public variable. I'm trying to assign it a value so i can use it down the line.

    The module this is in shows up in Access under Modules

    Thanks for your help!!!

    Chris

  5. #5
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    A sub seems to be a macro in Excel.
    That's true. In Word also, if you look at the code of a Macro - it will be in a Sub.
    But in Access it is best to get used to looking at them as two separate things - even though they both perform certain actions.

    As John_G said - it would help to know exactly what you want to do so we could tell you how you can achieve it.
    I have a feeling, though that a Function that returns and maybe also receives a value might be closer to what you need.

  6. #6
    cbh35711 is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Posts
    40
    How can i get a macro to show up in access? How can i declare it? I don't know any other way to declare it besides public sub() or sub().

    I'm trying to save the value from the form into a public variable(obligor_id).

    Thanks!

    Chris

  7. #7
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi Chris -

    You don't need a macro here - your one line of code does exactly what you want to do. (It's my own opinion, but I avoid MS Access macros at all costs!).

    The best place to put your code would be the after update event of the [Obligor_ID] control on the form.

    In the properties dialog for the control, scroll to After Update, select Event Procedure from the options, then click the "three dots" button to open the VB editor. You will see an "empty" sub, something like this:

    Private Sub Obligor_ID_AfterUpdate()

    End Sub

    Add your line of code to make it look like this:

    Private Sub Obligor_ID_AfterUpdate()
    Obligor_ID = Forms![Borrower Details]![Obligor_id]
    End Sub


    Save the code, and you're done. It's that easy.

    (If you knew how to code events already, sorry for the extra detail)

    I suggest that you change the name of the global variable, though, so that it is not the same name as the form control, otherwise Access might not get it right.

    HTH

    John

  8. #8
    cbh35711 is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Posts
    40
    I'm using tons of events now, but i didn't see a reason to use it here because they have to press a button anyway. So why not do everything i need to at once?

    How can i create a macro that shows up in the list? My only question

    Thanks!

    Chris

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

Similar Threads

  1. Macros
    By kstyles in forum Programming
    Replies: 2
    Last Post: 07-12-2011, 01:38 PM
  2. Macros??
    By Rosier75 in forum Programming
    Replies: 3
    Last Post: 02-01-2011, 01:55 PM
  3. Macros
    By Capri Pruitt in forum Access
    Replies: 1
    Last Post: 09-13-2010, 10:36 PM
  4. vba vs macros
    By RedGoneWILD in forum Access
    Replies: 4
    Last Post: 08-06-2010, 12:48 AM
  5. VBA vs Macros
    By Evgeny in forum Programming
    Replies: 3
    Last Post: 05-11-2010, 02:15 PM

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