Results 1 to 6 of 6
  1. #1
    griztkojr is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    30

    Changing a field value based on a new record


    Good afternoon,

    I have a form name frm_Employee with a subform name frm_EEWorkHIst. I would like to change a value of a field name [Job_Status] from Active to Inactive for all the records Active on subform frm_EEWorkHist when I am adding a new record to the subform. Any suggestions how I should go about this? Thank you.

    Click image for larger version. 

Name:	screen.PNG 
Views:	14 
Size:	102.8 KB 
ID:	32618

  2. #2
    Minty is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001
    I would probably use a separate cmd Button to achieve this, what if someone starts to add a new record then backs out of it, effectively cancelling the update.

    Or add an ADD new button that enables the sub form record adding functionality and confirm at that point that the existing records will be updated.
    Then its a simple VBA update query to adjust the existing records.

    Alternative data thought - why not have a deactivated date rather than an active flag. Then you would know when that task was either completed or unassigned?
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    griztkojr is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    30
    Thank you Minty. I am not VERY familiar with VBA coding. I started to put this together on the Click event
    Code:
    Private Sub Command291_Click()
    sSQL = "Select * From tbl_EEWorkHist WHERE EEID = " & Me.EEID
    Set RS = CurrentDb.OpenRecordset(sSQL)
    On Error GoTo resultsetError
    dbValue = RS!Variable
    MsgBox dbValue, vbOKOnly, "RS Value"
    resultsetError:
    MsgBox "Error", vbOKOnly, "Database Error"
    
    
    End Sub

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Why would the state of each record be dependent on another record of the same table? A job is either completed or it isn't. Why would assigning another job cause other jobs to 'reactivate'?
    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
    griztkojr is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    30
    Hi June7,

    If an employee is transferred to another job/assignment then the previous job gets "deactivated' and the new one becomes active and current.

    Quote Originally Posted by June7 View Post
    Why would the state of each record be dependent on another record of the same table? A job is either completed or it isn't. Why would assigning another job cause other jobs to 'reactivate'?

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Okay, I had it backwards.

    Is that field a text type?

    Can use an UPDATE query, something like:

    CurrentDb.Execute "UPDATE table SET [JobStatus]='Inactive' WHERE EmpID=" & Me.tbxEmp & " AND WorkID<>" & Me.tbxJob

    Along line of Minty suggestion, somehow confirm whether this action should occur. Either prompt the user or code can compare data and make the decision.

    Or just enter the data (department, date of assignment, etc). Then calculate the Active/Inactive status for each record. However, this concept may be a bit advanced for a novice to deal with.

    Advise not to use spaces nor punctuation/special characters (underscore only exception) in naming convention.
    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.

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

Similar Threads

  1. Replies: 3
    Last Post: 03-30-2017, 06:45 AM
  2. Replies: 5
    Last Post: 06-28-2013, 06:11 PM
  3. Replies: 2
    Last Post: 01-31-2013, 07:44 PM
  4. Replies: 1
    Last Post: 07-28-2011, 08:34 AM
  5. Changing tables based on field date
    By dssrun in forum Programming
    Replies: 6
    Last Post: 07-10-2011, 10:17 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