office_guru
Registered User.
- Local time
- Today, 17:20
- Joined
- Nov 17, 2004
- Messages
- 19
I'm discovering VB is so not my thing and I'd be lost without you all! Having said that, Please Help!
I had previously had a problem of opening a record where a record didn't exist on the same form - my code was sited as interesting code by one poster ;-) however it does work. Well now I'm trying to do something similiar but via multiple forms and now I'm having problems again.
I would like to open Form B (frm_pocs_review) from a link in Form A (frm_company_review) based on a common field (Company) on each form. If the record does not match want a message box to come up, so I can avoid the blank form (it's a no addition form so it comes up completely blank with no buttons/links to main menu), no record create new? Got that to work. If the record does match I want Form B to open on that record. - That's not working it's defaulting to the first record on Form B.
Can someone tell me where I'm going wrong? - Sorry in advance if the code in pain stakingly awful. :-/
Private Sub Label107_Click()
Dim rs As Object
Dim x
x = Me!Company
Dim frm As Form
DoCmd.OpenForm ("frm_POCs_Review")
Set frm = Forms!frm_POCs_Review
Set rs = frm.Recordset.Clone
rs.FindFirst "[Company] = '" & x & "'"
If rs.nomatch Then
Dim bytResponse As Byte
bytResponse = MsgBox("This record does not exist, would you like to create it?", vbYesNo + vbExclamation, "Not In List")
If bytResponse = vbYes Then
Response = acDataErrAdded
stDocName = "frm_pocs_input"
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.GoToRecord , , acNewRec
datefield = NewData
DoCmd.Close acForm, "frm_pocs_review"
ElseIf bytResponse = vbNo Then
Response = acDataErrContinue 'Show No message
End If
Else
Set rs = Me.Recordset.Clone
rs.FindFirst "[Company] = '" & x & "'"
End If
DoCmd.Close acForm, "frm_company_review"
End Sub
Thanks!
I had previously had a problem of opening a record where a record didn't exist on the same form - my code was sited as interesting code by one poster ;-) however it does work. Well now I'm trying to do something similiar but via multiple forms and now I'm having problems again.
I would like to open Form B (frm_pocs_review) from a link in Form A (frm_company_review) based on a common field (Company) on each form. If the record does not match want a message box to come up, so I can avoid the blank form (it's a no addition form so it comes up completely blank with no buttons/links to main menu), no record create new? Got that to work. If the record does match I want Form B to open on that record. - That's not working it's defaulting to the first record on Form B.
Can someone tell me where I'm going wrong? - Sorry in advance if the code in pain stakingly awful. :-/
Private Sub Label107_Click()
Dim rs As Object
Dim x
x = Me!Company
Dim frm As Form
DoCmd.OpenForm ("frm_POCs_Review")
Set frm = Forms!frm_POCs_Review
Set rs = frm.Recordset.Clone
rs.FindFirst "[Company] = '" & x & "'"
If rs.nomatch Then
Dim bytResponse As Byte
bytResponse = MsgBox("This record does not exist, would you like to create it?", vbYesNo + vbExclamation, "Not In List")
If bytResponse = vbYes Then
Response = acDataErrAdded
stDocName = "frm_pocs_input"
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.GoToRecord , , acNewRec
datefield = NewData
DoCmd.Close acForm, "frm_pocs_review"
ElseIf bytResponse = vbNo Then
Response = acDataErrContinue 'Show No message
End If
Else
Set rs = Me.Recordset.Clone
rs.FindFirst "[Company] = '" & x & "'"
End If
DoCmd.Close acForm, "frm_company_review"
End Sub
Thanks!