automatically create a table entry

rgreene

Registered User.
Local time
Today, 22:18
Joined
Jan 22, 2002
Messages
168
In my DB I'm tracking seed. I have a form that I enter in some info in and an ID number is created (based on that info). Then in a different form I track "events" that happen to that ID (drying, moved, bagged). Is it possible to have a button or something like that that after my ID is created from my frmHarvest to automatically generate an event in tblEvents that has the date the ID number and then have something like Harvested in the description field?

If possible can I get some hints on what to do?

Thanks,
Rick
 
Rick,

You can use your main form's AfterInsert event. It will fire after the
initial record is committed to the database.

Code:
DoCmd.RunSQL "Insert Into tblEvents (ID, Event, EventDate) " & _
             "Values (" & Me.ID & ", '" & Me.Event & "', #" & Now() & "#)"

hth,
Wayne
 
Thanks, I played with it last night but I just don't know enough about access to fugure out which of my stuff goes where in the inquiry. I create a LotID based on some info and stored in tblHarvest. tblHarvest's primary key is ADSID field. ADSID is the joining field in my tblEvents. so my entry needs to be the ADSID just created along with the EDate which is a date entered in my first table when I create the LotID, and also create an Event which could be hard coded as "Harvested" or something similar.

Like I said I tried plugging in different things for several hours last night but every time I'd get some type of error.


Thanks,

Rick
 
Last edited:
Rick,

Isn't this it?

Code:
      tblEvents Fields ----------------+------+--------+
                                       V      V        V
DoCmd.RunSQL "Insert Into tblEvents (ADSID, Event, EventDate) " & _
             "Values (" & Me.ADSID & ", 'Harvest', #" & Me.EDate & "#)"
                               ^                            ^
     Your form's fields -------+----------------------------+

If all else fails, post a sample DB.

Wayne
 
Nope I get a compile error
Method or data member not found

and the me.ADSID is highlighted
 
Rick,

All that means is that your primary key ADSID is not on your form.
Put it on your form, but make it invisible, then you can access its value.

Wayne
 

Users who are viewing this thread

Back
Top Bottom