Results 1 to 11 of 11
  1. #1
    Buakaw is offline Absolute novice
    Windows XP Access 2007
    Join Date
    Jan 2011
    Posts
    112

    Good programming practice wrt lookup tables?

    Hi
    I have a table, tblPaymentDetails storing details of customer transactions. One of these fields is the payment method, which is a number, called fkPaymentMethod.

    This number is actually a foreign key of another table called tblPaymentMethod.

    The fields of tblPaymentMethod are an Autonumber PrimaryKey, and a text description.



    In tblPaymentMethod we have:
    1 Cash
    2 Cheque
    3 Automated Bank Transfer

    and so on.

    So tblPaymentDetails.fkPaymentMethod will store numbers, 1, 2 and 3.

    In my programming, I want to create an enum that mirrors the entries in tblPaymentMethod. E.g.

    Enum PaymentType
    Cash = 1
    Cheque
    Automated_Bank_Transfer
    End Enum

    Problem is, this is not going to be sync'ed with the entries in tblPaymentMethod should tblPaymentMethod ever get updated.

    How can I solve this programming problem if I want to maintain some kind of integrity in my data so that someone's not going to update blPaymentMethod, and the Enum is not updated?

    Thanks.

  2. #2
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    Curious, why would you want or need to create an enum that mirrors the entries in tblPaymentMethod?

  3. #3
    Buakaw is offline Absolute novice
    Windows XP Access 2007
    Join Date
    Jan 2011
    Posts
    112
    To enable and disable other controls accordingly, for one.

    E.g. if Me.PaymentMethod = Check_Type, enable some controls, apend read value into table, else append something else into table.

  4. #4
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Why can't you do what you want (enable/disable or even hide controls)
    using the 1,2, 3 ?

    That's the PK in your tblPaymentMethod, so what's the issue.
    You can comment your code accordingly, if that's your concern.

  5. #5
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    I find it best to store this additional data in the tblPaymentMethod table so it is totally data driven not hard coded. Example: a flag field for check type. This way you can have multiple records of the same type and still will know how to handle them. This way it is not depended an the primary key value.

    For the UI I use a combo box to select the a Payment Method. I include the additional columns to hold the "flag" data in the row source. If you do not want the user to see them then you can set the column width to 0 to hide them.


    So the Enum is done by using the table. This avoids duplication of data.

    Quote Originally Posted by orange View Post
    Why can't you do what you want (enable/disable or even hide controls)
    using the 1,2, 3 ?

    That's the PK in your tblPaymentMethod, so what's the issue.
    You can comment your code accordingly, if that's your concern.
    This issue I have with that method is that you are hard coding the logic and not making it data/table driven.

    IMHO, hardcoding is not a "Good programming practice"

  6. #6
    Buakaw is offline Absolute novice
    Windows XP Access 2007
    Join Date
    Jan 2011
    Posts
    112
    Quote Originally Posted by HiTechCoach View Post
    I find it best to store this additional data in the tblPaymentMethod table so it is totally data driven not hard coded. Example: a flag field for check type. This way you can have multiple records of the same type and still will know how to handle them. This way it is not depended an the primary key value.

    For the UI I use a combo box to select the a Payment Method. I include the additional columns to hold the "flag" data in the row source. If you do not want the user to see them then you can set the column width to 0 to hide them.


    So the Enum is done by using the table. This avoids duplication of data.

    Coach, is it possible to provide an example so I understand what you mean? THanks.

  7. #7
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    I could made a sample database to show you the technique. It would probably benefit you a lot more if you were to post a sample of your database. Include at least the form, tables, etc that you working with. Remove any confidential data and include some sample data. Will you do that?

  8. #8
    Buakaw is offline Absolute novice
    Windows XP Access 2007
    Join Date
    Jan 2011
    Posts
    112
    Thanks for the help. Would it be possible to tell me briefly how it's done?

  9. #9
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    For the UI I normally use a combo box to select the a Payment Method. I include the additional columns to hold the "flag" data in the row source. If you do not want the user to see them then you can set the column width to 0 to hide them.

    I will assume the combo box has three columns in the row source:

    Name: cboPaymentMethod
    1) index(0) - Primary key - bound - width 0
    2) Index(1) - Description - seen by user
    3) index (2) - Type Flag

    In the combo box's After Update event and the form's on current event you could do something like this:


    Code:
    Select Case Me.cboPaymentMethod.Column(2) 
       Case "Check"
          Me.txtControlName.Visible = True
    ...   
    
    End Select

  10. #10
    Buakaw is offline Absolute novice
    Windows XP Access 2007
    Join Date
    Jan 2011
    Posts
    112
    Thanks Coach, I'll give it a try!

  11. #11
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    You're welcome.

    Let me know if you need any more assistance.

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

Similar Threads

  1. lookup tables
    By nkuebelbeck in forum Forms
    Replies: 3
    Last Post: 03-15-2010, 02:10 PM
  2. Lookup Tables
    By corinthianw in forum Access
    Replies: 1
    Last Post: 02-17-2010, 01:31 PM
  3. Microsoft Access Lookup tables
    By bitert01 in forum Forms
    Replies: 1
    Last Post: 02-20-2009, 02:55 PM
  4. lookup values in backend tables
    By deb56 in forum Database Design
    Replies: 1
    Last Post: 01-23-2008, 11:12 AM
  5. Lookup Tables
    By JoeBio in forum Database Design
    Replies: 1
    Last Post: 09-01-2006, 07:34 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