Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Susy is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2014
    Posts
    134

    vba ContactForm embedded on a MainForm


    Hi there,

    I created this main form which has many input drop-down fields. One of those drop-down fields is the contact field.

    The contact field is a table. The main form is a table which by ID is connected to the other tables (like contact table).

    The problem I have now is:

    If I were to delete one contact from the table (let say I created another form where the user can delete or modify the contact), then this contact is also gone from the main table.

    BUT, I DON't want that. Of course, modifications are allowed, so if someones last name changes, then this change should be reflected on the main table (mainform), but If I delete contacts which are not active anymore
    but I still want to have there past information, then I shoould be able to delete them without deleting them from the maintable.

    A hint how to do that? Delete contacts from the contact table but not from the maintable?

    Regards!

  2. #2
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    If I delete contacts which are not active anymore but I still want to have there past information, then I shoould be able to delete them without deleting them from the maintable.
    That doesn't make sense. If you delete a contact from the contacts table, then there is nothing (no record) for the main table to "point to", so you don't see any data. The contact information isn't in the main table, only a link to it is.

    The easiest way to prevent accidental loss of data is to create a relationship between the main table and the contacts table (it is probably one-to-many, but which is the "one" side in your case? ). The relationship should renforce referential integrity, but NOT allow cascade delete. With this arrangement, if you or someone else tries to delete a contact record that is referenced by a record in the main table, Access won't allow it, and give you an error message.

    If you need to keep historical data, just don't delete it. There is nothing wrong with having contact information that is not referenced anywhere in the main table.

  3. #3
    Susy is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2014
    Posts
    134
    Hi John_G,

    thanks... I still trying to follow (due to my lack of knowledge).

    When I delete something from the contacttable, it is also deleted in the maintable, till now. That is bad.

    Still thinking.......

    Regards!

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,900
    Have a field that flags contact as active or inactive. Then use filter to exclude inactive records.
    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
    Susy is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2014
    Posts
    134
    Hi Juna, sorry to ask... what do you mean with "flag a field as active or inactive" ?

    Is it like creating a drop-down menu where you create a field "HideShow" ( 0 or 1 ) and then create a query?

    Regards!

  6. #6
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    When I delete something from the contacttable, it is also deleted in the maintable, till now. That is bad.
    No, it isn't "deleted" from the main table, because it is not in the main table to begin with. Only a link (Contact_ID, perhaps?) to is, so when you delete a contact, the main table/form has a value that doesn't link anything. At least, that is the way it should be designed. Can you post the design of your main table?

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,900
    I mean a Yes/No or text type field that can be used to apply filter criteria so users are only offered active records to select. So a form or report RecordSource or combobox RowSource could be like: SELECT ContactID, ContactName FROM Contacts WHERE IsActive = True;
    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.

  8. #8
    Susy is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2014
    Posts
    134
    I did that... the problem is that the contact which I set as inactive cannot be seeing in the mainform (contact-drop-down menu). When I check the table main, the contact is there but not in the drop-down menu... and that is not nice... as I said, the drop-down menu is not empty it is just "empty but containing the contact which is now inactive.

    my Contact drop-down menu in the mainform as this properties:
    1. Control Source: ContactID

    2. Row Source:
    SELECT [ContactFName] & " " & [ContactLName] AS SOrgName, ContactPNumber, ContactID, IsInactive
    FROM tblContact
    WHERE (((tblContact.IsInactive)=False));

    3.RowSourceType: Table/Query

    4.BoundColumn: 3

    Any Ideas of how to fix this issue?

    But when I think it makes sense... the form just shows only those which are contact which are active...

    Regards,

  9. #9
    Susy is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2014
    Posts
    134
    As you will see Contacts No 2 and Contacts No 3 cannot be found on the mainreport... See attachment...
    Contactform gives the user the possibility to set contacts as active and inactive.

    This is just an idea what i am trying to avoid... to get empty fields from past records... you will understand and you see it :-)

    Thanks in advance.
    Attached Files Attached Files

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,900
    First, ContactID field in tbl_Main must be a number type because it is storing the ContactID from tbl_Contacts which is an autonumber.

    Change main form RecordSource to:
    SELECT tbl_Main.ReportID, tbl_Main.ReportNumber, tbl_Main.ContactID, [ContactFName] & " " & [ContactLName] AS CN
    FROM tbl_Contact RIGHT JOIN tbl_Main ON tbl_Contact.ContactID = tbl_Main.ContactID;

    Bind a textbox to the calculated CN field to display contact full name. Set the textbox as Locked Yes and TabStop No. The textbox can sit next to or on top of the combobox. If it is on top, user won't be able to click into the combobox. Could use code in textbox GotFocus event to immediately set focus to the combobox.

    There is no reason for user to see the ReportID field. Don't even need this on the form. Same for the ContactID on Contacts form.
    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.

  11. #11
    Susy is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2014
    Posts
    134
    Hi June,

    thanks, that is a nice approach.

    1. Question: Do I need to modify my table main as well... what I mean it that in tbl_Main in Design View I change the display control to: Combo Box, Row Source Type: Table/Query and RowSource to: SELECT [contactfname] & " " & [contactlname] AS ContactName, tbl_Contact.ContactPNumber, tbl_Contact.ContactID FROM tbl_Contact;

    ...because otherwise I get only one number (contact id) and not full contact name. Can you see the tbl_Main --- ContactID field?

    2. Question: In my main table (main form) I have at least 55 field (input fields, drop down menus) and not only the contact name can be set to inactive... there are other fields as well... and some fields are within a subform... which makes things -- I don't know yet, --- most likely complicated... anyway, the question is... Do I need to include every field in the Main Form RecordSource....? Instead of Select * from tbl_Main, ... I need to include every field I am using, creating...

    Thanks in advance!
    Attached Files Attached Files

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,900
    1. I never build lookups in table because I want to see the actual stored value when I view tables. Since users do not work directly with tables there is really no reason to show the alias.

    2. You have more lookup tables? You did not provide structure with 55 fields and other lookup tables. Apply the technique where needed. Yes, would have to include the other lookup tables in the query. Alternative is to use DLookup expression in textboxes. However, domain aggregate functions can perform slowly on form.
    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.

  13. #13
    Susy is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2014
    Posts
    134
    Yes, thanks, it is working great. Thanks again.

    to point 1 .... the query is in the table_Main in the field ContactID...

    If I leave field ContactID as text then it would look like this:
    Click image for larger version. 

Name:	text_ContactID.JPG 
Views:	16 
Size:	19.4 KB 
ID:	30338

    but when change to a combobox and with the query posted above.. it looks like this:
    Click image for larger version. 

Name:	combox_lookup_ContactID.JPG 
Views:	16 
Size:	58.0 KB 
ID:	30339

    Click image for larger version. 

Name:	combobox_ContactID.JPG 
Views:	16 
Size:	20.2 KB 
ID:	30340

    Should I modify the tables as well?

    Nice weekend!

  14. #14
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,900
    That's up to you. I explained my preference and why. Do what works best for you. If you use the filtered RowSource in table, alias will not show for the 'inactive'. So, no, don't need to do the same setup for the table.
    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.

  15. #15
    Susy is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2014
    Posts
    134
    You are right... either way when I query the information I get the ids and not the text directly...

    Thanks

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Search subform from mainform
    By ittechguy in forum Programming
    Replies: 70
    Last Post: 10-04-2015, 06:08 AM
  2. Can i get subform total on mainform
    By muhammadirfanghori in forum Forms
    Replies: 3
    Last Post: 03-23-2015, 05:56 PM
  3. Link between subform and mainform
    By crowegreg in forum Forms
    Replies: 2
    Last Post: 08-24-2011, 07:05 AM
  4. MainForm/SubForm question
    By 10 Gauge in forum Forms
    Replies: 5
    Last Post: 03-04-2011, 07:46 AM
  5. Replies: 0
    Last Post: 03-14-2009, 12:33 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