Add new record(fk) to a related record(pk) from cmd button event

M

MaryF

Hello,

I hope you can assist...I have been working on this for a few days and am now totally frustrated.

I have a cmdSSOpenRel button on frm_SystemSheet. I want the frm_SystemSheet OnClick event to open the corresponding system record in tbl_Release/frm_Release. What I also want to do is if there is no corresponding record in tbl_Release, to then ask the user if they wants to create the data for that particular system, and if so, open a blank frm_Release where they can enter the data for that corresponding system. (It is a one (SysID) to many (Rel_SysID) 2K relationship.)

Below is the code:

Private Sub cmdSSOpenRel_Click()

Dim stLinkCriteria As String
Dim rst As Object, dbs As Object
Dim mbrResponse As VbMsgBoxResult
Dim Newdata As String
Dim strMsg As String
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tbl_Release")

stLinkCriteria = "[Rel_SysID]=" & Me![SysID]
DoCmd.OpenForm "frm_Release", , , stLinkCriteria

' I think I need an If Then but cannot figure out the correct statement
' ??? If "Rel_SysID" = 0 then??
strMsg = Newdata & "There is no release data for this system, would you like to add this information?"
mbrResponse = MsgBox(strMsg, vbYesNo + vbQuestion, "New Release")
Select Case mbrResponse
Case vbYes
'Add new release record'
Datamode:=acFormAdd, _
Windowmode:=acDialog, _
OpenArgs:=Newdata
Case vbNo
Exit Sub
End Select
' End if
End Sub

When I click the cmd button, the frm_Release opens and then shows the strMsg, even if there is a related record. (I need the message to only show if there is no related record.) And, if the user clicks on Yes, the frm_Release then stays open but does not create a record with a RELATED Rel_SysID, only a new record with a Rel_SysID=0. Can anyone help, please?

(P.S. If I create a frm_Release Subform within frm_SystemSheet it works fine. But I do not want to view the release info all the time, only if the user wants to see it, so this is not a good option.)

Thank you very much,
Mary :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top