Results 1 to 6 of 6
  1. #1
    erlan501 is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2010
    Posts
    4

    Updating another record table with command button

    Greetings.. I'm new in access. I had a little problem and I can't solve it.



    I had a form that have a command button to add a record, but I need it to change a value on another record from another table. So when I click the add record button not only new record created but it also change the value on another table.

    In my case when I add a new record from that form I also want to change another record value from default value "available" to become "Unavailable" automatically.

  2. #2
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    Well I need a proper understanding of your problem. Can you give me more details about the relationships of your tables and the fields involved. Perhaps you can also give a small example.

  3. #3
    Evgeny's Avatar
    Evgeny is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Apr 2010
    Posts
    85
    can you post a sample of your db to look at. Regards

  4. #4
    erlan501 is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2010
    Posts
    4
    In example :

    I had a table "Link Activation" (ID, Activation date, Port, Terminal Name). The "Port" field related to a table "Terminal Port List"(ID, Port, Status==> Combo box with value="available" and "unavailable").

    And I made a form from this "Link Activation" table and add a command button "activate the link" in the form.

    What I want is when I hit the command button "activate the link" , the "status" field from Terminal Port List is change, from "available" to become "unavailable".

  5. #5
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    Quote Originally Posted by erlan501 View Post
    In example :

    I had a table "Link Activation" (ID, Activation date, Port, Terminal Name). The "Port" field related to a table "Terminal Port List"(ID, Port, Status==> Combo box with value="available" and "unavailable").

    And I made a form from this "Link Activation" table and add a command button "activate the link" in the form.

    What I want is when I hit the command button "activate the link" , the "status" field from Terminal Port List is change, from "available" to become "unavailable".
    I assume that the following:
    1) When you select a Port on the form record Source Link Activation the Status for the Port in the Terminal Port List will become unavailable form available.

    I have tried to replicate the condition:
    I have two tables and In Terminal Port List I have the names of the Ports and the status is available.

    On the Form I have a Button Names update status with the following Code:
    Private Sub Command8_Click()
    On Error GoTo Err_Command8_Click
    Dim IntRetVal As Integer
    Dim strSQL As String
    IntRetVal = SysCmd(acSysCmdSetStatus, "Running Query Now")
    strSQL = "UPDATE Terminal_Port SET Status ='unavailable' Where ID=" & Me.PortID
    CurrentDb.Execute strSQL
    IntRetVal = SysCmd(acSysCmdSetStatus, " ")

    Exit_Command8_Click:
    Exit Sub

    Err_Command8_Click:
    MsgBox Err.Description
    Resume Exit_Command8_Click

    End Sub

    Here in the above Code I have used an update query to update the statues of te port.


    You can use RecordSet. Update Status 1 uses RecordSets

    Private Sub Command9_Click()
    On Error GoTo Err_Command9_Click
    Dim strSQL As String
    strSQL = "Select * From Terminal_Port Where ID=" & Me.PortID
    Set rs = CurrentDb.OpenRecordset(strSQL)
    If rs.EOF And rs.BOF Then
    Exit Sub
    Else
    rs.Edit
    End If
    rs!Status = "unavailable"
    rs.Update
    rs.Close
    Set rs = Nothing
    Exit_Command9_Click:
    Exit Sub

    Err_Command9_Click:
    MsgBox Err.Description
    Resume Exit_Command9_Click

    End Sub

    Both of the does the same thing.

    Attaching a sample mdb for your reference.

    Mark the thread solved if this solves your problem.


    How to use the sample A startup form will open select a Port from the port combo and Click any of the update buttons see the effect in the tables
    Last edited by maximus; 04-26-2010 at 04:25 AM.

  6. #6
    erlan501 is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2010
    Posts
    4
    I still can't make it work..I post the file, could someone please help me to make it work??

    I want to change the value in the Status field in the Terminal Port List table to become unavailable when I hit the Add Reocrd button.

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

Similar Threads

  1. how to disable command button
    By archie in forum Access
    Replies: 1
    Last Post: 08-27-2009, 11:11 PM
  2. Command button help - delete record
    By Zukster in forum Forms
    Replies: 0
    Last Post: 08-27-2009, 08:47 AM
  3. Command Button Help!
    By arthura in forum Programming
    Replies: 3
    Last Post: 06-30-2009, 12:55 PM
  4. Duplicate command button
    By brettg in forum Database Design
    Replies: 1
    Last Post: 08-04-2008, 04:16 AM
  5. Command button code
    By lfolger in forum Forms
    Replies: 3
    Last Post: 03-25-2008, 04:26 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