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

Create new record from form...

Status
Not open for further replies.

gacollier

IS-IT--Management
Feb 5, 2004
192
US
Looking for help defining an OnOpen Event procedure that will work with a form to do the following:

First off, this particular form will only be opened by another form via a button.

Once the form is opened, I'd like the OnOpen event to determine automatically if the record is new or existing. If the record is new, I'd like for it to create a new record without having to enter any data, (currently if I open the form and the record is new I have to enter some data in at least one field then save before I can continue, I'm trying to eliminate that step.)

Any thoughts on how I might accomplish this?
 
Have you tried to test the NewRecord property of the form ?

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV,

Thanks for the response. Yes, I do know if the record is new, and have an "If" statemenet built and ready to go, but I can't seem to find the right VBA code to save the new record so it creates a new record number.

Greg
 
PHV,

Here's what I eneded up doing.

I created a table item called "Stuff" and inserted it into my form. I then check to see if the record is new. If it is I assign the "Stuff" item a string and it creates a new PK number.

Here's the code.


Code:
Private Sub Form_Open(Cancel As Integer)
   
' set the MainId to match the Main order

    MainID.DefaultValue = Forms!Main!MainID
    If IsNull(OrderID) Then
        MsgBox "This is a new record"
        Stuff.SetFocus
        Stuff = "Test"
    End If

End Sub,

There's has to be a cleaner way to do this, but I just don't know what it is.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top