Page 1 of 7 1234567 LastLast
Results 1 to 15 of 98
  1. #1
    deepaksharma is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Jul 2023
    Location
    india
    Posts
    389

    sub form data not find

    I have created a form and a sub form in it. main form table name is grey_offer and sub form table name is grey_shade. Table named grey_offer has 16 column after this when i type the back id number in the id column the old data is show and i can edit it and save then the data gets updated.
    Now the problem comes here that when i type back id number and press enter, then data is shown in the main form but the data of the related sub form is not shown and the sub form remains empty with only new current id.
    How can i solve this problem? my coding for searching the data is as follows.....

    Private Sub TXT0_AfterUpdate()
    SQL = "SELECT*FROM GREY_OFFER WHERE ID = " & Me.TXT0


    Set DB = CurrentDb
    Set RST = DB.OpenRecordset(SQL)
    If RST.RecordCount > 0 Then
    For DATACOL = 0 To 15
    Me("TXT" & DATACOL) = RST.Fields(DATACOL)
    Next
    End If
    End Sub


    and save button code is follow-

    Option Compare Database
    Private ASAVED As Boolean
    Dim DB As DAO.Database
    Dim RST As DAO.Recordset




    Private Sub SAVE_Click()

    Set DB = CurrentDb
    Set RST = DB.OpenRecordset("GREY_OFFER")

    If (IsNull(Me![txt2].Value)) Then
    MsgBox ("PLEASE ENTER VALUE")
    Exit Sub
    End If

    If Me.txt2 = "" Then
    MsgBox ("PLEASE ENTER VALUE")
    Exit Sub
    End If

    If Me.TXT0 = 1 Then GoTo ADDNEW

    If DMax("ID", "GREY_SHADE") + 1 >= Me.TXT0 Then GoTo ADDNEW

    RST.MoveFirst
    Do Until RST.EOF
    If RST.Fields(0) = Me.TXT0 Then
    RST.EDIT

    For DATACOL = 0 To 15
    RST.Fields(DATACOL) = Me("TXT" & DATACOL)
    Next DATACOL

    Dim answer As Integer
    answer = MsgBox("Do you Wish to UPDATED data?", vbQuestion + vbYesNo + vbDefaultButton1, "User Repsonse")
    If answer = vbYes Then
    RST.Update
    End If

    Me.Undo
    DoCmd.RefreshRecord
    Me.TXT0 = DMax("ID", "GREY_OFFER") + 1
    Me.txt1.SetFocus

    Exit Sub
    End If
    RST.MoveNext

    Loop


    ADDNEW:

    If Me.TXT0 < 1 Then
    MsgBox ("ID NUMBER NOT TO BE 0")
    Me.Undo
    Me.TXT0 = DMax("ID", "GREY_OFFER") + 1
    Me.TXT0.SetFocus

    Exit Sub
    End If

    If DCount("*", "GREY_SHADE", "ID = " & Me.ID) < 1 Then
    MsgBox ("PLEASE ENTER SHADE")
    Me!GREY_SHADE.Form.SHADE.SetFocus
    SendKeys "+{TAB}"
    Exit Sub
    End If



    ASAVED = True

    MsgBox ("data save successfully")

    DoCmd.RunCommand (acCmdRecordsGoToNew)
    Me.TXT0 = DMax("ID", "GREY_OFFER") + 1
    Me.TXT0.SetFocus

    End Sub
    Attached Thumbnails Attached Thumbnails id.png  
    Last edited by deepaksharma; 08-03-2023 at 02:06 AM. Reason: for missing code

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Is control TXT0 for the ID? Is it UNBOUND? Controls used to enter/select search/filter criteria must be UNBOUND otherwise you change data in record.


    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.

  3. #3
    deepaksharma is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Jul 2023
    Location
    india
    Posts
    389
    yes control txt0 is for id and main form and sub form link with id

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Please start using code tags for anything more than one line of code.

    1. Why are you not using bound forms?
    2. Why is the subform not linked to main form with Master/Child links?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    deepaksharma is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Jul 2023
    Location
    india
    Posts
    389
    subform is alreday linked with main form.

  6. #6
    deepaksharma is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Jul 2023
    Location
    india
    Posts
    389

    please see...

    please see..
    Attached Thumbnails Attached Thumbnails id2.png  

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by deepaksharma View Post
    subform is alreday linked with main form.
    Hmm, upload the DB then.
    BTW having the autonumber field called ID all the time is bad practice.
    Give them some meaninful names. Access will get confused as well.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  8. #8
    deepaksharma is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Jul 2023
    Location
    india
    Posts
    389
    ok...
    sir please check it...
    Attached Files Attached Files

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by deepaksharma View Post
    ok...
    sir please check it...
    Sorry, too late for me.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  10. #10
    deepaksharma is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Jul 2023
    Location
    india
    Posts
    389
    Please try when you have time

  11. #11
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by deepaksharma View Post
    Please try when you have time
    No, I mean the version is later than mine, and I am unable to open and run it.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  12. #12
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I can open with Access 2010. Don't know why can't open with 2007.

    There is no Private Sub TXT0_AfterUpdate() code in the posted db.

    As already advised, control used to enter/select search/filter criteria must be UNBOUND otherwise you change data in record. Use UNBOUND controls in form header for search. Review http://allenbrowne.com/ser-62.html

    Why is ID field in GREY_OFFER not an autonumber? Why is there a 0 ID record? A field named ID is commonly accepted to indicate a field with unique values. This is not the case with GREY_SHADE table. This table's ID field is a foreign key for GREY_OFFER ID value. Give the fields better names, like: OfferID and OfferID_FK. Both of these textboxes should be set as LOCKED and TAB STOP No to prevent user edit or don't have these textboxes at all.

    You have designed other tables without autonumber key field and instead of saving a key you are saving text into GREY_OFFER. This does simplify queries as there is no need to join tables but uses more storage for the data. That may not be an issue if your db does not grow to 2GB.

    Might want to rename OFFER_ENTERY to OFFER_ENTRY.

    Also, field named SELVAGE might should be SALVAGE. Two words with very different meanings.

    Using all upper case is not advised as it is harder to read. Also advise not to use spaces in naming convention as you have in field names.

    In future, please post code between CODE tags. Use the # icon on post edit toolbar.
    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
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    It just tells me features used which are not supported and stopped me opening that form.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  14. #14
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Yes, I have encountered that issue before. I just can't determine what is used by this db that 2007 can't handle.

    Try opening with shift key bypass.
    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
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by June7 View Post
    Yes, I have encountered that issue before. I just can't determine what is used by this db that 2007 can't handle.

    Try opening with shift key bypass.
    Yes, shift Bypass allows me to open form in design view, but when I try form view it says I need Access 14.
    Sounds like you have it all in hand anyway?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. Replies: 9
    Last Post: 04-26-2019, 08:17 PM
  2. Replies: 6
    Last Post: 04-16-2018, 09:15 PM
  3. Replies: 3
    Last Post: 09-01-2015, 04:36 AM
  4. Replies: 7
    Last Post: 06-12-2012, 08:56 AM
  5. Replies: 5
    Last Post: 03-03-2011, 03:56 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