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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Programatically adding a new or updating a record

Status
Not open for further replies.
Jul 24, 2000
88
CA
Hi fellow Access users,

In Access XP, when the user is filling out the fields for a new record on a form, one of the options I have is to go to a child form to fill out some detail there. My experience with Access shows that this new 'child' form only works well if the parent form has added the new record before work is done on the child form. Is this experience shared by others?

Given that it is, can I can programmatically open the recordset as was suggested to me last year, and examine the .acNewRecord property to determine whether to add a new or update an existing record?

Thanks for any help you can give.

Richard
 
How are ya RichardBott . . . . .
RichardBott said:
[blue] . . . [purple]this new 'child' form only works well if the parent form has added the new record before work is done on the child form.[/purple] Is this experience shared by others?[/blue]
Yes . . . all of us! It has to do with [blue]relationships between tables[/blue]. The rule is:
Microsoft said:
[blue]You can't save a record in a Child Table, without a corresponding record in the Parent Table.[/blue]
Now . . . I don't know which event your using, but for say . . . a command button, it would be something like this:
Code:
[blue]   Dim Msg As String, Style As Integer, Title As String
   Dim NL As String, DL As String, flg As Boolean
   
   NL = vbNewLine
   DL = NL & NL
   flg = True
   
   If Me.NewRecord Then
      Msg = "You have entered a new Parent record!" & DL & _
            "You can't save a child unless the Parent is saved!" & DL & _
            "Click 'Yes' to save the Parent and continue." & DL & _
            "Click 'No' to cancel and abort . . ."
      Style = vbInformation + vbYesNo
      Title = "New Record Detected! . . ."
      
      If MsgBox(Msg, Style, Title) = vbYes Then
         DoCmd.RunCommand [b]acCmdSaveRecord[/b]
      Else
         flg = False
      End If
   
   End If
   
   If flg Then DoCmd.OpenForm "[purple][b]YourFormName[/b][/purple]"[/blue]

Calvin.gif
See Ya! . . . . . .
 
Hi TheAceMan1 and thanks for the info! I shall use the "If Me.NewRecord Then..." construct to prompt the user to save the new record.

Thanks again,
Richard

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top