Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2007
    Posts
    214

    Question Unanswered: coding a form with imported data

    Hi All,

    I have a form that uses a table that I automatically imported data to. For instance, I imported all data from an excel file using the "import" opton on the file menu.

    Well, there is one field called "term code" which displays a code that means something more specific. I want to be able to code another text box to display the actual meaning so we don't have to refer to the term code cheat sheet all the time.

    I've tried:

    if termcode = "H5" then
    text123 = "Detailed meaning of code"
    elseif termcode = "H7" then
    text123 = "Detailed meaning of code"

    and so on...

    end if



    The above code does not work. I'm not sure if I'm having this trouble because the data was automatically imported from excel, or what.

    Please let me know any ideas.

  2. #2
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    It doesn't matter where the data comes from.

    The correct way to do this is to have a related table TERMCODE that has the term code and the description. Then you can just link your table with the TERMCODE table and you're done. No coding required.

    However, again I have to ask what "the above code does not work" means. Does it run? Does it give an error message? Does it provide the wrong data?
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  3. #3
    Join Date
    Oct 2007
    Posts
    214
    It means that the code does nothing. It does not give an error it just does not run. To my knowledge, it should work. I've used if statements in similar ways to code my other forms and they have run perfect.

  4. #4
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    "just does not run"
    which event is this code attached to?

    izy
    currently using SS 2008R2

  5. #5
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    I personally like to use syntax like this (but I doubt this is your problem)...

    if me!termcode = "H5" then
    me!text123 = "Detailed meaning of code"
    else
    if me!termcode = "H7" then
    me!text123 = "Detailed meaning of code"

    and so on...

    end if

    It's most likely due to whatever event is calling this peice of code and that event not firing (ie. field not updating, form not updating/refreshing, or whatever is tied to the code.)

    You can always throw in a few msgbox "I'm here in the code" at places in the code you want to check (or msgbox "TermCode = " & me!termcode)
    Last edited by pkstormy; 10-13-08 at 19:53.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  6. #6
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Quote Originally Posted by benz1984
    It means that the code does nothing. It does not give an error it just does not run. To my knowledge, it should work. I've used if statements in similar ways to code my other forms and they have run perfect.
    So find out why the code doesn't run! Set a breakpoint in the code and try it, see if the code is even being looked at... then step through it with F8 and examine the contents of variables and watch how the interpreter follows your logic. You should find the answer pretty quickly that way.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  7. #7
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    put a watch on the code and make certain the code is being executed
    and/or put an else clause at the end fo your if statement (or better yet use a select case)

    Code:
    select case ucase(termcode)
    case is = "H5":text123 = "Detailed meaning of code"
    case is = "H7":text123 = "Detailed meaning of code"
    case else
    text123 = "not problems found"
    'or you could do
    text123 = "Termination code: & termcode & " not found"
    'or
    msgbox "Termination code: & termcode & " not found"
    end select
    you don't say how this code is used, either as a function, in line code or whatever.
    if its a function make certain you have called the function...... theres many a time I've been swearing at why code doesn't work to find I'd forgotten to call a function or sub, or Ive called the wrong one...
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

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