New Record Not Saving

G

Guest

When I load a form (from another form), in a one to many situation, if there is not a record found, the form is loaded with the two pieces of info (required for linking) and the current date is placed into the appropiate field. The indicator (upper left corner) shows that the record is saved, but it has not been (looked in the table to verify). I have a command button there to save the record, but that button also does not save the record until I enter some data and then manually save it.

The code in the save button follows. the commended out line was written by Access 2000 and the line after it was what I wrote in trying to solve the problem. Neither works.

Private Sub fmOrientSaveRec_Click()
On Error GoTo Err_fmOrientSaveRec_Click
' DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.RunCommand acCmdSaveRecord
Exit_fmOrientSaveRec_Click:
Exit Sub
Err_fmOrientSaveRec_Click:
MsgBox Err.Description
Resume Exit_fmOrientSaveRec_Click
End Sub

Thanks,
John H W
 
A

Al Borges

When I placed a clickbutton on a test form with the :

DoCmd.RunCommand acCmdSaveRecord

it saved the record to the underlying table just fine...

Regards,
Al

John H W said:
When I load a form (from another form), in a one to many situation, if
there is not a record found, the form is loaded with the two pieces of info
(required for linking) and the current date is placed into the appropiate
field. The indicator (upper left corner) shows that the record is saved,
but it has not been (looked in the table to verify). I have a command
button there to save the record, but that button also does not save the
record until I enter some data and then manually save it.
The code in the save button follows. the commended out line was written
by Access 2000 and the line after it was what I wrote in trying to solve the
problem. Neither works.
 
A

Allen Browne

If a form is at a new record, and nothing has been entered, there is nothing
to save. That is true even if you see the Default Value property displaying
something in the controls.

The user needs to type something into one of the controls on the form before
the new record can be saved. Alternatively, you can programmatically assign
a valule to a control in order to dirty the form, e.g.:
Forms![SomeDateField] = Date()

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

John H W said:
When I load a form (from another form), in a one to many situation, if
there is not a record found, the form is loaded with the two pieces of info
(required for linking) and the current date is placed into the appropiate
field. The indicator (upper left corner) shows that the record is saved,
but it has not been (looked in the table to verify). I have a command
button there to save the record, but that button also does not save the
record until I enter some data and then manually save it.
The code in the save button follows. the commended out line was written
by Access 2000 and the line after it was what I wrote in trying to solve the
problem. Neither works.
 
G

Guest

This makes sense Allen; when you refer to the default value property, don't you mean this is the difference in that .Value and .Text, the .Value is chars in ctl, not necessarily a reflection of field row entry in the underlying tables?
 
A

Allen Browne

Fair enough.

I should have said:
... even if you see a value displayed in the control due to its
DefaultValue property.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Jim Shores said:
This makes sense Allen; when you refer to the default value property,
don't you mean this is the difference in that .Value and .Text, the .Value
is chars in ctl, not necessarily a reflection of field row entry in the
underlying tables?
 
G

Guest

My two months experience with VBA and Access, following ya'lls help and users questions and my own, the concept is challenging. One would like to imagine the ctls on forms are pure windows to whatever fields they reflect.
Can you think of a simple way to use conditional formatting, changing the background color of txtBox, to then allow the user to know what they were looking at in a form+subform's edit controls?
I put the following in both before & after update events and it didn't do anything useful for me.Set ctl1 = Me.fsubTransactionDetail

If ctl1.Form.Recordset.RecordCount > 0 Then
ctl1.Form.Recordset.MoveFirst
Me.txtRowOneMoney = ctl1.Form.Controls("txtCreditAmount")
End If

Set ctl1 = Nothing 'does this help mem leaks?
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Jim Shores
82°r BHM
 
A

Allen Browne

Jim, I would not do this with conditional formatting, as you are very likely
to trigger an endless calculation loop, or even have controls that are
disabled receiving focus. Details:
http://allenbrowne.com/bug-05.html

The safe way to do this for a single-view form is to use the GotFocus and
LostFocus events of each control to call a function which highlights and
restores them:

Public Function Highlight(ctl As Control, bHighlighted As Boolean)
If bHighlighted Then
ctl.BackColor = vbYellow
Else
ctl.BackColor = vbWhite
End If
End Function

Now to assign the code to the events of all the text boxes and combos on the
form, run this once, passing in the name of the form you want this to apply
to:

Function SetupHightlight(strForm As String)
Dim ctl As Control
Dim strName As String

DoCmd.OpenForm strForm, acDesign
For Each ctl In Forms(strForm).Controls
Select Case ctl.ControlType
Case acTextBox, acComboBox ', and other types if you wish
strName = ctl.Name
ctl.OnGotFocus = "=HighLight([" & strName & "], True)"
ctl.OnLostFocus = "=HighLight([" & strName & "], False)"
End Select
Next
Set ctl = Nothing
End Function

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Jim Shores said:
My two months experience with VBA and Access, following ya'lls help and
users questions and my own, the concept is challenging. One would like to
imagine the ctls on forms are pure windows to whatever fields they reflect.
Can you think of a simple way to use conditional formatting, changing
the background color of txtBox, to then allow the user to know what they
were looking at in a form+subform's edit controls?
 
G

Guest

Allen that's great,
I am beginning to trust our community enough to leave your foregoing just excellent exposition in place until I can apply try to apply it.
I did follow but you said single-view and I think that means, 'not counting, say, two subforms'. Might there be a message the main form could hear from the subforms and then inquire about the contents of the subform controls? Or maybe vice-versa?
I have been catching up on entrys and the standard behavior isn't as bad as it seemed a day and two ago
Jim
(25°C)BHM
 
A

Allen Browne

If you use the code with the continuous form or datasheet, it highlights the
entire column, not just the active text box of the current record.

Re your final comment, you certainly get the fastest and most stable
projects if you can work with the way Access works.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Jim Shores said:
Allen that's great,
I am beginning to trust our community enough to leave your foregoing
just excellent exposition in place until I can apply try to apply it.
I did follow but you said single-view and I think that means, 'not
counting, say, two subforms'. Might there be a message the main form could
hear from the subforms and then inquire about the contents of the subform
controls? Or maybe vice-versa?
 

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