Results 1 to 15 of 15

Thread: Class Module

  1. #1
    Join Date
    Feb 2005
    Location
    The Hague, Netherlands
    Posts
    95

    Unanswered: Class Module

    Hi,

    Is it possible to call a sub or routine thats in a class module of another form? I admit, I havent grasped the concept of modules yet, but it would probably have been better to put such code in some global module?

  2. #2
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Yes you can as long as the function or sub is Public ... You'll also need to qualify the name also ...
    Back to Access ... ADO is not the way to go for speed ...

  3. #3
    Join Date
    Feb 2005
    Location
    The Hague, Netherlands
    Posts
    95
    Quote Originally Posted by M Owen
    Yes you can as long as the function or sub is Public ... You'll also need to qualify the name also ...
    What would be the syntax? I have to specify where Access has to go look for the sub, do I need to name the form or smt?

    Call frm!PublicSub <-- smt like that?

    thx

  4. #4
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Quote Originally Posted by avlan
    What would be the syntax? I have to specify where Access has to go look for the sub, do I need to name the form or smt?

    Call frm!PublicSub <-- smt like that?

    thx
    That is what qualify means .... Yes.
    Back to Access ... ADO is not the way to go for speed ...

  5. #5
    Join Date
    Feb 2005
    Location
    The Hague, Netherlands
    Posts
    95
    Quote Originally Posted by M Owen
    That is what qualify means .... Yes.
    You've been here far too long m8, go play with your keyboard or smt.

    Anyone any USEFULL advise like the actual working syntax? thx

  6. #6
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Quote Originally Posted by avlan
    You've been here far too long m8, go play with your keyboard or smt.

    Anyone any USEFULL advise like the actual working syntax? thx
    And my advice (tho cryptic) was not useful???? I did tell you EXACTLY what you needed to do ... An example:

    Forms![New Account Entry II].UpdateTxt_AfterUpdate


    CAVEAT: The form must be active (open) in order to invoke any of it's methods ...
    Back to Access ... ADO is not the way to go for speed ...

  7. #7
    Join Date
    Sep 2003
    Location
    The extremely Royal borough of Kensington, London
    Posts
    778
    Is it good practice to place all non form related code in modules or classes.

    To call form methods from outside the form, search for the function 'CallByName'
    Bessie Braddock: Winston, you are drunk!
    Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.

  8. #8
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    my thoughts on this:
    yes and no
    ...depends on what the code does.

    if you have some run-once code (check references, get username, setup stuff, relink tables, read config tables, etc) then you might be better off placing it in a form (even tho you don't want to see the form). that way the cxode unloads from memory when the form closes.

    otherwise, general use stuff that your application uses regularly from different forms should be in a module. keep related routines together in their own module - once A loads one routine in a module it loads the whole module and it stays there until your pc crashes or your app quits.

    normaly it does not make sense to have general use stuff on one form unless that form is permanently loaded... why take the additional perfomance hit of bringing in the grafix part of the form everytime you need to use the routine.

    izy
    currently using SS 2008R2

  9. #9
    Join Date
    Feb 2005
    Location
    The Hague, Netherlands
    Posts
    95
    Quote Originally Posted by M Owen
    And my advice (tho cryptic) was not useful???? I did tell you EXACTLY what you needed to do ... An example:

    Forms![New Account Entry II].UpdateTxt_AfterUpdate


    CAVEAT: The form must be active (open) in order to invoke any of it's methods ...
    Heh only that it doesnt work, and I hate it when ppl are being smartasses. "can you pass me the salt?" -"sure I can." THEN DO SO

    Anyways, thanks for your (cryptic) advice but it doesnt seem to work.

    I simply have a form (that will always be open) where I have a number of 'standard' subs or functions, like: The user chooses a roomnumber from a dropdown on the form, I need to know which ID (in my tables) corresponds with this roomnumber so I wrote a function which retrieves it from my DB.

    However, now I have another smal form, which opens when a user wants to edit his/her 'used software'-list, and in this form, I ALSO need to find the corresponding roomID with the roomnumber. I'd like to use the function I wrote in my main form, but "call mainfrm!functionname(var)" doesnt seem to work (I'll check the error)...

  10. #10
    Join Date
    Feb 2005
    Location
    The Hague, Netherlands
    Posts
    95
    ok... apparently

    Call Forms!Her.GetMainIDFromDDgebruikers(USR)
    ID = Forms!Her.GetMainIDFromDDgebruikers


    does not work but

    ID = Forms!Her.GetMainIDFromDDgebruikers(USR)

    Does.
    So, a sub or function on another form, you can not 'call' but you have to assign the value directly to a variable

  11. #11
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Quote Originally Posted by avlan
    Heh only that it doesnt work, and I hate it when ppl are being smartasses. "can you pass me the salt?" -"sure I can." THEN DO SO

    Anyways, thanks for your (cryptic) advice but it doesnt seem to work.

    I simply have a form (that will always be open) where I have a number of 'standard' subs or functions, like: The user chooses a roomnumber from a dropdown on the form, I need to know which ID (in my tables) corresponds with this roomnumber so I wrote a function which retrieves it from my DB.

    However, now I have another smal form, which opens when a user wants to edit his/her 'used software'-list, and in this form, I ALSO need to find the corresponding roomID with the roomnumber. I'd like to use the function I wrote in my main form, but "call mainfrm!functionname(var)" doesnt seem to work (I'll check the error)...
    Me a smartass? What is your intent for calling the sub or function? Are you trying to do something to the current form using the other form's sub? If so, then you can't ... When you call another form's sub, it works on that form not on the one you're currently in ... As for calling/invoking a function: you cannot make public functions on forms ... Access doesn't allow it and as such, you cannot call or invoke a private function of another form ...

    ... I hate it when ppl are being smartasses. "can you pass me the salt?" -"sure I can." THEN DO SO
    I answered the question ... I can't help it if you ask the wrong question (or the right question wrongly).

    My thoughts on help in this forum: No one owes you a thing ... If they do then it's a good thing. I usually help by pointing someone in the right direction or posting a bit of sample code that I wrote that has the general idea of how to do it ... I don't do people's work for them. I don't answer completely obvious questions. I assume that every poster on this forum is a programmer/developer and as such I assume that they have the training/knowledge/experience to solve their problem ... If they don't, I DO NOT CARE. If someone feels that I'm not helping them enough: I DO NOT CARE!!!

    I help out because I know that at some point in the future I'll have a question (or a bad day) and will need that little nudge to get me going in the right direction ...
    Back to Access ... ADO is not the way to go for speed ...

  12. #12
    Join Date
    Jul 2004
    Location
    Inverurie
    Posts
    628
    Smartass - someone who can sit on an ice cream and tell you what flavour it is.

    Honetly, if you can't understand the help given, ask for clarification in a polite manner. I don't think you'll get anywhere by ranting and raving.

  13. #13
    Join Date
    Feb 2005
    Location
    The Hague, Netherlands
    Posts
    95
    Quote Originally Posted by cruickshanks
    Smartass - someone who can sit on an ice cream and tell you what flavour it is.

    Honetly, if you can't understand the help given, ask for clarification in a polite manner. I don't think you'll get anywhere by ranting and raving.
    Apparently you have never seen me ranting and raving

    With all do respect, if you cant give help in an understandable way, then dont give help.

    In this case, M Owen was giving vague hints of me being on the right track without actually giving up all the information and knowledge he has. This does not help me. If I have to post 3 times asking the same question just because someone is having fun in being cryptical and playing around, I just as well had not posted and used my time checking out yet another tutorial or the google groups. I DID in the end check Google groups and through what someone posted THERE I found the solution. Now, you can tell me whatever you want, but thats a pretty bad result for this forum. I assume everyone here on the forum wants to keep this forum and wants this forum to be the number one spot for Access users to go when they have a question.

    M Owen, as I said, thanks for your help, my only irritation was that you were playing games more then you was trying to help. As stated above, if I want a nice puzzle, I'll go read the Da Vinci Code. I post here if I have tried a numbers of things, read a few tutorials but still have problems in getting things to work.

    Apart from that, I hate ppl who act like they know everything but can't explain it to a newb in a normal way or even look down on such a person for asking. You did not do that, but you scratched the surface I know I overreact in such cases, so, sorry about that.

    I answered the question ... I can't help it if you ask the wrong question (or the right question wrongly).
    My initial question was:
    Is it possible to call a sub or routine thats in a class module of another form?

    Ok my bad that I didnt ask for the syntax to do so. You answered accordingly:

    Yes you can as long as the function or sub is Public ... You'll also need to qualify the name also ...
    Ok, so then I ask: What would be the syntax? I have to specify where Access has to go look for the sub, do I need to name the form or smt?
    Call frm!PublicSub <-- smt like that? thx

    And then you reply:
    That is what qualify means .... Yes.
    We can beat around the bush and say you were being nice, but this is a smartass reply. This is saying: "Thats what I SAID the first time stupid" in a nice way.

    Obviously, I have tried the 'Call frm!PublicSub'-part and it didnt work. So if then, you reply in a way like this, I'm like: kthxbye. This is no help. I'm here asking a normal question and you're wasting my time, since I now know 'call frm!publicSub' doesnt even work, but you apparently didnt know either OR didnt bother to correct. Which is fine, but then say: "I dont know" or dont post at all imo.

    I don't answer completely obvious questions. I assume that every poster on this forum is a programmer/developer and as such I assume that they have the training/knowledge/experience to solve their problem ... If they don't, I DO NOT CARE. If someone feels that I'm not helping them enough: I DO NOT CARE!!!
    Thats all nice and cosy but then DONT POST!!! If you think this is an obvious question DONT REPLY!! I'm not asking you to do my work, but a forum like this is typically helpful for syntax errors or practical problems like the use of certain commands etc. The thinking about what I need to make; how my DB is organized and what color the form should be; This is what I will happily do myself, if I want to call a sub in another form and have a suspicion this is possible but have no clue what the command or syntax could be, FIRST I try Access Help and some websites, if that doesnt work, I come here and ask the simple question.

    You might wanna do the next assumption in all your assumptions: If a question is asked here, you can assume the person who asked does not know the answer.

  14. #14
    Join Date
    Jul 2004
    Location
    Inverurie
    Posts
    628
    That's a little obvious though, and it does appear that more than one person overreacted in here. I simply tried to put a funny aspect on it to try and calm things down.

    Anyway, there is the other problem here: Some people here know that much about these things that they may put up a syntax that'll confuse you, but unless you ask for a little clarification because you've never come across this way of doing the job. Although someone may flame you, but they generally don't do that here.

    For instance, someone's explained the same thing to me in three different ways (if you search for posts made by me you'll see what i mean) before i actually understood it and corrected the problem.

  15. #15
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Avlan,

    I'm being cryptic and playing games? I do admit to having "fun" at the expense of someone who asks the wrong question to which I give them a completely correct but entirely useless answer ... But in your case, I did answer correctly even tho you did not understand my answer. Now, is it my responsibility to teach you what I said? Or even explain it in terms that you can understand? No ... (BTW: I've worked with a whole host of programmers who understand what "qualify" means in the context that I wrote it ...)
    Back to Access ... ADO is not the way to go for speed ...

Posting Permissions

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