Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OpenForms function

Status
Not open for further replies.

Form1

Programmer
Apr 27, 2005
12
I'm using OpenForms function to open form B with specific record from form A.

If the record is present in Form B then
it should show the record and allow user to update
else if not present
then user should be allowed to enter new record in Form B

Function OpenForms(strFormName As String) As Integer

dim stLinkCriteria as String

stLinkCriteria = "[Id]" = & Me!Id

DoCmd.OpenForms strFormName,,,stLinkCriteria,,,Me!Id

With Forms.item(strFormName)
.AllowAdditions = true
.AllowDeletions = True
.AllowEdits = True
End With

End Function

The above solution does not work. Is there any other way to do it.

I can not use acAdd it add new record every time.

Thanks
 
How are ya Form1 . . . . .

Your [blue]DoCmd.OpenForm[/blue] uses the last arguement ([purple]OpenArgs[/purple]) to pass the ID to formB. Disable the code that uses [purple]Openargs[/purple] in formB, then try the following:
Code:
[blue]Function OpenForms(strFormName As String) As Integer
  
   Dim frm As Form, rst As DAO.Recordset
   
   DoCmd.OpenForm strFormName
   Set frm = Forms(strFormName)
   
   With frm
      .AllowAdditions = True
      .AllowDeletions = True
      .AllowEdits = True
   End With
   
   Set rst = frm.RecordsetClone
   rst.FindFirst "[Id]=" & Me!Id
   
   If rst.NoMatch Then
      DoCmd.RunCommand acCmdRecordsGoToNew
   Else
      frm.Bookmark = rst.Bookmark
   End If
   
   Set rst = Nothing
   Set frm = Nothing
  
End Function[/blue]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top