Full Version: Form Opens With Pencil Icon
UtterAccess Forums > Microsoft® Access > Access Forms
Brandi
Is there some property that makes a form open with the pencil icon?
I want the form to open in a normal mode where the arrow appears next to the record rather than the pencil icon.

Thank you.
Brandi
theDBguy
Hi Brandi. It won't be a property. You must have some code that's dirtying the form as it opens. To avoid that, try setting Default Values instead.
Garfieldm842
http://www.tek-tips.com/viewthread.cfm?qid=927411

The pencil simply means that the editing changes have not been committed to the table. So, for example, pressing escape can undo the changes.

If you put a button on a form with the wizard enabled and select the wizard option for save record it will generate code behind the button that includes the following line:


CODE
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Whether that code actually helps you depends on what event will tell Access that it is time to save the data to the table.
Brandi
The Save record code seems to work but for my future reference, where would you set Default Values.

Thank you both for your replies.

Brandi
Garfieldm842
Under the data tab of a form you can set the default value for a control.

In a table you can also set the default value for fields.
gemmathehusky
I am sure it won't be a default value. default values don't set until a new record is created.

you must have some code that is setting a control/fields value when the form opens.
Brandi
OK. thank you all. I'll stick with the save record for now. I can't see where I am doing anything to put it in edit mode but this will solve it.

Brandi
theDBguy
Hi Brandi. Are you saying there is no code running when you open the form?
Brandi
The only code running is the OnCurrent event which you are helping me with for another reason.
The form opens with a photo of an employee. I still can't get a hyperlink to a photo to open but the code below works if I tie the name of the employee photo to their empl ID.

Private Sub Form_Current()
On Error GoTo err_proc
Dim strFileName As String
If Nz(Me.[Empl ID], 0) = 0 Then
Me.Photo = ""
Exit Sub
End If

strFileName = Application.CurrentProject.Path & "\Images\" & Me.[Empl ID] & ".jpg"
If Dir(strFileName) = "" Then
'MsgBox "Cannot find image file"
Me.Photo = ""
Exit Sub
End If

Me.Photo = strFileName

exit_proc:
Exit Sub

err_proc:
MsgBox Err.Description
Resume exit_proc

End Sub
theDBguy
Okay. If "photo" is a name of a field or control on the form, then the code Me.Photo='something' is causing your pencil icon because you are assigning a value to a bound field that dirties the record. Does that make sense?
Brandi
So adding a save record command is the right thing to do?
theDBguy
Actually, I think setting a default value is more appropriate. For example, instead of Me.Photo="", try: Me.Photo.DefaultValue=""
Brandi
I am getting an error on Me.Photo.DefaultValue = ""

It is highlighting the word DefaultValue.
theDBguy
Is Photo a field or a bound control on your form? Try also: Me.Photo.DefaultValue=""""""
Note: That's six (6) double quotes in a row.
pere_de_chipstick
PMFJI

>>So adding a save record command is the right thing to do?<<
I would have thought that saving the record was exactly the wrong thing to do!

if you are saving a record because it has become 'dirty' for an unknown reason then potentially you could be saving incorrect data.

From what you have posted your control 'Me.Photo' is a bound control which should be unbound. You should then not need any default value, but should retain the 'On Current' Event you already have.

hth
gemmathehusky
if you really want that code, it would be better in the beforeinsert event, maybe, so that it runs only when you add a new record, rather than when you go to the new record row.
pere_de_chipstick
Hi Dave

I read the OP as having an image control that needed to be loaded if an image was available in a folder, and cleared if there was no current ID or if there was no image; see the OPs code:
CODE
strFileName = Application.CurrentProject.Path & "\Images\" & Me.[Empl ID] & ".jpg"
If Dir(strFileName) = "" Then
'MsgBox "Cannot find image file"
  Me.Photo = ""
   Exit Sub
End If
Me.Photo = strFileName


As far as I can see there is no need for the image control to be bound and the On Current event is the correct place for the code (?)
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.