OnSubmitRequest / OnSaveRequest with Access

D

dinsoftbd

I have an access database as my primary data source for my Infopath form. The
form will add / update the database table when I hit the Submit button. But,
now I want to add code to do insert today's date in either the add_date or
update_date fields (depending on if this is a new record, or an existing
record). I don't know if I should be adding this code to the onSubmitRequest
event or the OnSaveRequest, and how to get the data to then save. Each
variation I have tried from code samples found on the web result in errors.
 
S

S.Y.M. Wong-A-Ton

Have you tried doing it without code? Here are my 2 cents on this subject....

I don't know how you have your form set up, but you could leave both
add_date and update_date invisible to the user, that is, not include them in
the form's view, since these fields need to be automatically filled in. You
can then add a Default Value to add_date that uses a formula with the today()
function to pre-populate it whenever a new record is added. Remember that you
may have to format the value of today() by using the substring() and concat()
functions for the date to concord with the format of the field in your db
table (see
http://enterprise-solutions.swits.net/infopath/date-time-basics-infopath.htm
and http://enterprise-solutions.swits.net/infopath/solutions.htm#datetime for
more information and samples on using date functions in InfoPath). For the
update_date field you need to add a rule to each field in a record. These
rules must set the value of update_date to today() and format it just like
you did for the add_date field. So update_date field will be filled for new
records as well as changed for existing records whenever the data in a field
of a record is edited.

If you still want to do it through code, I would suggest using the
OnAfterChange event to set the udpate_date field (see
http://enterprise-solutions.swits.net/infopath/retrieve-field-value-same-row-repeating-table.htm
for a sample on how the retrieve a field, i.e., update_date field in your
case, that is in the same row as the field being edited) and the
OnSubmitRequest to fill the add_date for all records where it doesn't have a
value. For this you would have to loop through the rows of your data source,
inspect each add_date field for each row, and do the update.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top