Add and View SetFocus question (1 Viewer)

lightray

Registered User.
Local time
Today, 17:06
Joined
Sep 18, 2006
Messages
270
Sorry if this has come up before, I have been chasing dozens of threads that are so close, I've still not got it!:eek:

I have a form that is used in edit mode and add mode. When used in edit mode it has a combo box in the header that does the usual bookmark search in the after update event, and on open focus is set to this field in the open form event.

When in add mode i don't want this set focus to happen so I'm not sure what the test statement should be.:confused:

Would appreciate a pointer or two.
lightray
 

WalterInOz

Registered User.
Local time
Today, 15:06
Joined
Apr 11, 2006
Messages
93
I include a textfield named "setfocus" on forms and set focus to that upon opening forms such as described by you.
 

lightray

Registered User.
Local time
Today, 17:06
Joined
Sep 18, 2006
Messages
270
Thanks for your reply Walter, What I am wanting to test I think, is if the form is open in acFormEdit or acFormAdd mode. not much of idea how to put the test together.
lightray
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 06:06
Joined
Sep 12, 2006
Messages
15,641
you can test the values of me.allowedits and me.allowadditions when you open the file. (among many others)

just put me. and all the available options will be shown
 

lightray

Registered User.
Local time
Today, 17:06
Joined
Sep 18, 2006
Messages
270
Thanks gemma, so my syntax is a test for true?

If me.allowedits = True then .... else .... etc :)

BTW working late? 16:40 here
 

lightray

Registered User.
Local time
Today, 17:06
Joined
Sep 18, 2006
Messages
270
Well my code started out alright then hit a snagg!

If Me.AllowEdits = True then
Me.cboEmployee.SetFocus
Else
Me.[JobTitleID].???? only gives me the option of value?

anyone tell me what I'm missing? lightray :confused:

Edit: It would help if I picked a Name on the playing field... should have been
Else
Me.LastName.SetFocus
And then .....
If Me.AllowAdditions = False then

otherwise all working as specified. ;)

Edit: Well spoke to soon. Seems fixed on the on the LastName field for both modes

any ideas? anyone? ;(
 
Last edited:

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 06:06
Joined
Sep 12, 2006
Messages
15,641
Are you fixed lightray?

not clear what yuo are trying to do now, from your last post?
 

lightray

Registered User.
Local time
Today, 17:06
Joined
Sep 18, 2006
Messages
270
Sorry gemma, fire fighting on a few fronts here. Thanks for getting back, primarily I am trying to set a condition so that if form is in edit mode it does A, else it will most likely be in Add mode so do B
My final code was:
If Me.AllowAdditions = False then
Me.cboEmployee.SetFocus
Else
Me.LastName.SetFocus
End If
Placed in the Form_Open event. The result was to fix it in Me.LastName.Setfocus. Something wrong there, do I need a Cancel?
lightray
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 06:06
Joined
Sep 12, 2006
Messages
15,641
you need the code in the form CURRENT event. each time you goto a new record, the current event fires.

I am not sure, because your code may work, but it is possible that at the time of the openevent the form opens, but the first record is not yet loaded, and trying to setfocus to a particular field may fail. You definitely however only get the openevent (or loadevent) once per form. Access help will show the sequence of events somewhere actually.
 

lightray

Registered User.
Local time
Today, 17:06
Joined
Sep 18, 2006
Messages
270
Putting it in the Current event didn't change anything. Surely if you can just set it once for the form mode Edit or Add(it):) that it will ripple through once set? Doesn't work in open or load events either, anyway. :(

Will have to settle for leaving it in the LastName field, better for when Adding new records.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 06:06
Joined
Sep 12, 2006
Messages
15,641
i see

in the form properties there are a number of properties

allow filters
allow edits
allow deletions
allow additions
data entry

it is these that are being tested. if you are inedit mode, then alomst certainly additions are enabled also. hence you will probably will be setting focus in the lastname

-------------------
possibly you want something to test whether you are editing a NEWRECORD, and it definitely should be in the current event to test each record.


if me.newrecord then
'set focus appropriately
else
'set focus appropriately
end if

note - just putting me.newrecord implicitly tests if me.newrecord=true
 

lightray

Registered User.
Local time
Today, 17:06
Joined
Sep 18, 2006
Messages
270
Bingo! gemma that was right on the mark. Thanks for your time.. :)
lightray
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 06:06
Joined
Sep 12, 2006
Messages
15,641
one final thought then

dataentry is another option on the form properties, underneath the ones already discuussed. you may not have realised exactly what it did.

when a form opens, if you open it in "data entry" mode, then you can only add newrecords to the table, and not see or edit previously existing records. I am not sure if you are aware of that.
 

lightray

Registered User.
Local time
Today, 17:06
Joined
Sep 18, 2006
Messages
270
gemma-the-husky said:
when a form opens, if you open it in "data entry" mode
So that's the acFormAdd of the DoDcmd right?

A further Q? When you are in Edit Mode and you can add a new newrecord, does the AllowEdits condition toggle (True/False switch) to AllowAdditions? or does one condition remain overall ie the AllowEdits?

Thanks again, this Post has helped me solve two other issues, lightray:)
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 06:06
Joined
Sep 12, 2006
Messages
15,641
i'm not sure about these, as I don't think i've ever changed then dynamically. I'm sure they work independently though. The default in Access is for all actions to be permitted. Certainly however, Allow edits doesn't of its own allow additions also. eg, You may have a table that you are happy to let users modify, but not to add new entries, or delete items. Hence you set (in the properties - allowedits to true, and allowdeletions, and allowadditions to false)

i'm not sure what you mean by the acformadd of the docmd. ithe setting for the form to be a entry form (ie allow new items only, and not display previous items) is me.dataentry

look at Access help for more info. Don't know if anyone else finds this, but I think A97 help is far easier to use than later helps.
 

lightray

Registered User.
Local time
Today, 17:06
Joined
Sep 18, 2006
Messages
270
gemma-the-husky said:
i'm not sure what you mean by the acformadd of the docmd.

When you execute the DoCmd one of the parameters after the [Where] parameter you can specify how the form will be opened;
acFormAdd; acFormEdit; acFormReadOnly; and one other

I am not changing anything dynamically I was just wondering what happens when you open a Form DoCmd ,,,acFormEdit and then click the * button to add a new record, does the condition of Me.AllowEdits=True switch to Me.AllowEdits=False and Set Me.AllowAdditions=True? (from False)

It appears that it switches, and probably rightly so.
Here's what I'm trying to do
Code:
Private Sub Designation_AfterUpdate()
    If Me.AllowAdditions = True Then
    Me.DivisionID = Forms!frmEmployees!DivisionID
    Me.StartDate = Forms!frmEmployees!EmpStartDate
    Me.LocationName.SetFocus
    End If

End Sub
When a new employee rec is added, there will also be a new job rec added.
because there is relevant info on the main form, I want to pass it to the Job form (saves retyping) this should only happen for the first ever Job rec not subsequent ones which will have different start date and possibly different divn.
obviously when I create a new job rec for the employee this will/is happen/ing again. am I doing the test wrong? maybe a DLookup?:(
 

Oldsoftboss

AWF VIP
Local time
Today, 15:06
Joined
Oct 28, 2001
Messages
2,499
I was heading down this same track some time ago. I found the amount of code required to differenciate between the edit form and add form was getting out of hand. My suggestion is make a copy of the form, call one frmAdd, one formEdit, set the approprate properties for each, then you dont need any code !

Dave
 

lightray

Registered User.
Local time
Today, 17:06
Joined
Sep 18, 2006
Messages
270
Thanks Oldsoftboss I was starting to turn that way, you've supplied the nudge I need. Not so big forms so will be a breeze. ;)
 

Users who are viewing this thread

Top Bottom