I have a form ("Clients") that points to a "Clients" table. I also have a form ("AddEditClient") that points to same table.
Open Clients form and you see client info. Have at the bottom 2 buttons. One to create a new client and one to edit the current client. B/c we do not want user to edit clients from main client form (most fields are locked on this form). So if the user clicks on "edit client" button takes them to same record on AddEditClient form... now they can edit the client (fields are not locked). If they click the "add client" button it takes them to a blank new record on the AddEditClient form. To this point all is good.
On the AddEditClient form there is only one button ("Finished" button). If they were editing an existing client I want it to return them to the same record on the client form and making sure to display the new data. If they added a new client then I want it to display that new client on the client form. If selected the new client button but then did not add a new client and simply hit finished then it opens the client form on the first record of the client table. I have it half way working right.
My problem is that if they added a new client then it does not send them back to that client. I think I need a REQUERY statement... but it seems that no matter where I put it, it breaks my opening of the correct record and then starts sending me back to the first record of the client table. Here is my code for the "Finish" button on the AddEditClients form. Where does the requery statement go (and what is the proper syntax)? (or if this is a bad way to do this... how am I "suppose" to do it?) Also I read on another thread something about opening the second form in "Dialog" mode... this keeps it so that the second form would have to be closed to get back to the first form. I think this would be a good thing to do here to... how do I do that?
Thanks for any help you can give!!!
Open Clients form and you see client info. Have at the bottom 2 buttons. One to create a new client and one to edit the current client. B/c we do not want user to edit clients from main client form (most fields are locked on this form). So if the user clicks on "edit client" button takes them to same record on AddEditClient form... now they can edit the client (fields are not locked). If they click the "add client" button it takes them to a blank new record on the AddEditClient form. To this point all is good.
On the AddEditClient form there is only one button ("Finished" button). If they were editing an existing client I want it to return them to the same record on the client form and making sure to display the new data. If they added a new client then I want it to display that new client on the client form. If selected the new client button but then did not add a new client and simply hit finished then it opens the client form on the first record of the client table. I have it half way working right.
My problem is that if they added a new client then it does not send them back to that client. I think I need a REQUERY statement... but it seems that no matter where I put it, it breaks my opening of the correct record and then starts sending me back to the first record of the client table. Here is my code for the "Finish" button on the AddEditClients form. Where does the requery statement go (and what is the proper syntax)? (or if this is a bad way to do this... how am I "suppose" to do it?) Also I read on another thread something about opening the second form in "Dialog" mode... this keeps it so that the second form would have to be closed to get back to the first form. I think this would be a good thing to do here to... how do I do that?
Private Sub FinishedAdd_EditButton_Click()
On Error GoTo Err_FinishedAdd_EditButton_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Clients"
If Me![ClientK_ID] > Null Then
stLinkCriteria = "[ClientK_ID]=" & Me![ClientK_ID]
DoCmd.Close
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
DoCmd.Close
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
Exit_FinishedAdd_EditButton_Click:
Exit Sub
Err_FinishedAdd_EditButton_Click:
MsgBox Err.Description
Resume Exit_FinishedAdd_EditButton_Click
End Sub
On Error GoTo Err_FinishedAdd_EditButton_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Clients"
If Me![ClientK_ID] > Null Then
stLinkCriteria = "[ClientK_ID]=" & Me![ClientK_ID]
DoCmd.Close
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
DoCmd.Close
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
Exit_FinishedAdd_EditButton_Click:
Exit Sub
Err_FinishedAdd_EditButton_Click:
MsgBox Err.Description
Resume Exit_FinishedAdd_EditButton_Click
End Sub
Thanks for any help you can give!!!