Results 1 to 8 of 8
  1. #1
    decco21 is offline Novice
    Windows 8 Access 2013
    Join Date
    Feb 2015
    Posts
    7

    Editing a single record via selection on a form

    Hi all,



    I just can't get my head quite around how to use a form to select a specific record from a table for editing on its own.

    I am building a .mdb (2003-2007) in Access 2013. Originally I used a split form for this because Access 2013 doesn't take this functionality away even though I'm saving as a 2003-2007 file but because Access 2003 doesn't support split forms I am unable to do this (and any attempts to replicate the split form with subforms have just had me frustrated and I've given up on that idea).

    My first form Edit a Drawing search (see below) prompts the user to select a Job Number from combobox JobNumber which populates via the SELECT DISTINCT function from the main table Drawing List. Another combobox DrawingNumber then filters based on the Job Number selection (as I only want the user to be able to edit a record that already exists in the database.

    Click image for larger version. 

Name:	Edit a Drawing search.PNG 
Views:	11 
Size:	4.5 KB 
ID:	19736

    On clicking 'Edit Drawing', I want the following form Edit a Drawing to appear (see below) with the textboxes populated with the fields from the record selected on the Edit a Drawing search form, allowing the user to change all fields and then save the record. For this second form I've tried using something like the code below but to no avail - it always seems to be pulling up the first record or no record at all.

    Click image for larger version. 

Name:	Edit a Drawing.PNG 
Views:	11 
Size:	6.4 KB 
ID:	19737

    Any help would be really appreciated at this point! Thanks

    Code:
    Private Sub Form_Load()
        DoCmd.OpenTable "Drawing List"
        DoCmd.SearchForRecord acDataTable, "Drawing List", acFirst, Me.JobNumber = [Forms]![Edit a Drawing search].[JobNumber]
    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Also, you should use the click event of the "Edit Drawing" button of the "Edit a Drawing search" form, NOT the form load event of the "Edit a Drawing" form.

    I always use a saved query or a SQL string for the form record source, never a table.

  4. #4
    decco21 is offline Novice
    Windows 8 Access 2013
    Join Date
    Feb 2015
    Posts
    7
    Quote Originally Posted by pbaldy View Post
    Thanks again pbaldy! I gave it a shot but I'm a bit of a rookie so getting a little confused. Am I going to need it to look at the primary key value of the record from the table as this is the only unique identifier for the particular record (i.e. if I direct it at Job Number or Drawing Number it could be multiple records)? If so, do I need to add a control that stores the primary key value (ID in table Drawing List)?

    I tried just implementing it looking at the Job Number with the following code, but I get a VBA error.

    Code:
    Private Sub EditButton_Click()    DoCmd.OpenForm "Edit a Drawing", , , "Job Number = " & Me.JobNumber
    End Sub
    I also tried this with the extra quotes in case VBA recognised it as text, but to no avail.

    You have my database from a different thread if this helps


    Quote Originally Posted by ssanfu View Post
    Also, you should use the click event of the "Edit Drawing" button of the "Edit a Drawing search" form, NOT the form load event of the "Edit a Drawing" form.
    Thanks ssanfu, I think I used to have it like this but changed it a while ago, possibly because it wasn't working and I was clutching at straws :P

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    It is text, and the inadvisable space in the field name requires it be bracketed:

    DoCmd.OpenForm "Edit a Drawing", , , "[Job Number] = '" & Me.JobNumber & "'"

    You'll find in the long run that the spaces in your names are not worth the trouble.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    decco21 is offline Novice
    Windows 8 Access 2013
    Join Date
    Feb 2015
    Posts
    7
    Haha, I have already found that they aren't worth it, mate. Cheers for that.

    It works well, but there's still the question of when there are multiple drawings for a single job number. If you select a drawing number, whilst you can cycle to that, I really would like it to focus initially on the record selected on the Edit a Drawing search form to avoid mistakes when users edit.

    Is there a way to include multiple whereconditions?

  7. #7
    decco21 is offline Novice
    Windows 8 Access 2013
    Join Date
    Feb 2015
    Posts
    7
    Quote Originally Posted by decco21 View Post
    Is there a way to include multiple whereconditions?
    Took me a while to figure this out, but, quite simply, you just put an "and" in the code. However, this meant both comboboxes had to be filled in Edit a Drawing search for anything to appear in Edit a Drawing. To overcome this, I used the following code (for anyone who might find it helpful).

    Thanks again Paul and Steve for all your help!

    Code:
    Private Sub EditButton_Click()
    
    
    Dim strWhere As String
     
        If Len(Me.JobNumber & "") > 0 Then
        strWhere = "[Job Number]='" & Me.JobNumber & "' "
        End If
        
        If Len(Me.DrawingNumber & "") > 0 Then
        strWhere = "[Drawing Number]='" & Me.DrawingNumber & "' "
        End If
        
        If strWhere <> "" Then
            If Len(Me.DrawingNumber & "") <> 0 Then
                If Len(Me.JobNumber & "") <> 0 Then
                    strWhere = "[Job Number]='" & Me.JobNumber & "' And  [Drawing Number]='" & Me.DrawingNumber & "'"
                Else
                    strWhere = "[Drawing Number]='" & Me.DrawingNumber & "'"
                End If
            End If
        End If
        
        DoCmd.OpenForm "Edit a Drawing", , , strWhere
        DoCmd.Close acForm, "Edit a Drawing search", acSaveNo
    
    
    End Sub

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Send Single Record From Form
    By kristijo in forum Access
    Replies: 3
    Last Post: 12-02-2014, 06:24 PM
  2. Replies: 4
    Last Post: 11-07-2011, 07:25 PM
  3. Replies: 1
    Last Post: 09-27-2011, 09:42 PM
  4. Replies: 1
    Last Post: 09-27-2011, 09:05 PM
  5. Replies: 0
    Last Post: 10-16-2008, 02:39 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