Unsaved Record in Main Form (1 Viewer)

wilderfan

Registered User.
Local time
Yesterday, 23:12
Joined
Mar 3, 2008
Messages
172
I have two forms, the first of which I'll refer to as my "main" form. The main form has 6 text boxes bound to Table1.

There is a one-to-many relationship between the records of Table1 and the Dates table.

After filling out the first 2 text boxes of the main form, I want to open up a second form to populate the Dates table. I'm using OpenArgs to pass through the PK of Table1, so that it can be recorded in the Dates table.

Sometimes I'll want to enter a 2nd or 3rd date, but I am getting an error message after entering the 1st date. It says that Access cannot find a matching key in the main table.

Is there a way for me to save the record in the Table1 prior to opening
the second form so that I can avoid the error message?

NOTE: I don't want to use a subform to enter the dates because I don't care for the datatable look of subforms. After entering the dates in the second form, I then want to go back to the main form to complete entering the remaining text boxes.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 23:12
Joined
Aug 30, 2003
Messages
36,118
You may find continuous forms view preferable to datasheet for a subform, but in any case you can force a save with:

If Me.Dirty Then Me.Dirty = False

With a subform, Access takes care of the linking field for you.
 

wilderfan

Registered User.
Local time
Yesterday, 23:12
Joined
Mar 3, 2008
Messages
172
Thanks, Paul.

As always, you are a wealth of knowledge.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 23:12
Joined
Aug 30, 2003
Messages
36,118
Happy to help!
 

wilderfan

Registered User.
Local time
Yesterday, 23:12
Joined
Mar 3, 2008
Messages
172
I've run into further complications. (What else is new?)

When I open up the 2nd form which is used to input dates, everything works fine until I try to input a second date.

I think one problem relates to the passing of info using OpenArgs. I have successfully split the OpenArgs string into 4 pieces of info, 2 of which I have saved in a couple of variables defined within the Load event.

In the After Update event for the Date text box, I use a MsgBox to ask the user if he/she wants to record a second date. That's when the trouble starts.

So I'm wondering if I should be passing the OpenArgs string into something other than the Load event of the 2nd form. Or perhaps I should be defining my variables in the Declarations area instead of within the Load event.

There are a couple of other problems, as well:

1) After saying "Yes" to adding another date, the set focus goes to the 1st control on the 2nd form rather than the text box for Dates. I've tried to keep the focus on the Dates text box in the After Update event. But that clearly doesn't work.

2) Getting another error message about the table related to the 1st form not having an ID for the 2nd date that I am trying to enter in the 2nd form. Sounds like I need to use the Dirty event again, but I'm not sure where to insert that.

Any suggestions / advice would be much appreciated.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 23:12
Joined
Aug 30, 2003
Messages
36,118
Again, the subform does this work for you. It sounds like you need code in the current event that puts the key field from OpenArgs in on any new record. I'd probably put them in form level variables in the open or load events so you only have to parse them out once.
 

wilderfan

Registered User.
Local time
Yesterday, 23:12
Joined
Mar 3, 2008
Messages
172
Inserting some Current Event coding for the 2nd Form worked.

I simply "called" the Form Load event within the current event and that seemed to work.

Thanks again, Paul.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 23:12
Joined
Aug 30, 2003
Messages
36,118
Happy to help!
 

Users who are viewing this thread

Top Bottom