Results 1 to 3 of 3
  1. #1
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2003
    Join Date
    Jun 2016
    Posts
    237

    updating a field based on value in a subform

    Hi to all

    I have two bounded forms: main form with a subform.
    the subform has different records based on a value from the main form.

    I want to update a field. I used an AfterUpdate event as follows:

    Code:
    Private Sub txtDateReturned_AfterUpdate()
    
     Dim rstLibrary As Recordset
     Set rstLibrary = CurrentDb.OpenRecordset(Name:="tblBooks", Type:=RecordsetTypeEnum.dbOpenDynaset)
    
    On Error GoTo ProcError
    
    ' Update Status Book to show that is is returned
        Dim strReturned As Long
        strReturned = Me.cboBookTitle.Column(0)
        
        Debug.Print "strReturned = "; strReturned
        
    
        If Not IsNull(Me.txtDateReturned) Then
    
        DoCmd.RunSQL "UPDATE tblbooks SET fkBookStatusId = 1 WHERE pkBookId=strReturned"
        
        Else
        ' do nothing
        End If
        
    ExitProc:
        Exit Sub
    ProcError:
        MsgBox "Error " & Err.Number & ": " & Err.Description, _
              vbCritical, "Error in procedure AfterUpdate Event..."
        Resume ExitProc
    
    End Sub



    Running the code gives a dialogue box titlesd: (Enter parameter value) and is asking me write the value of strReturned.
    I need to type the value of the pkBookId of that record example: 20150 and it will work.
    What is wrong in my code?

    Khalil

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    you cant put the variable inside the quotes:
    "UPDATE tblbooks SET fkBookStatusId = 1 WHERE pkBookId=" & strReturned

  3. #3
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2003
    Join Date
    Jun 2016
    Posts
    237
    Yes,
    It worked. Thank you

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

Similar Threads

  1. Replies: 31
    Last Post: 05-29-2017, 08:21 AM
  2. Replies: 3
    Last Post: 06-24-2015, 12:57 PM
  3. Replies: 4
    Last Post: 12-29-2014, 01:53 PM
  4. Updating one date field based on another
    By barryg80 in forum Forms
    Replies: 4
    Last Post: 04-19-2013, 03:17 AM
  5. Updating subform based on combo box change
    By kev921hs in forum Forms
    Replies: 3
    Last Post: 04-01-2010, 08:43 AM

Tags for this Thread

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