Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / June 2007

Tip: Looking for answers? Try searching our database.

If...ElseIf

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
BonnieW - 31 May 2007 20:57 GMT
I'm having a heck of a time with this form & form-switching.

I have a form called "tablepeople" (I didn't name it- I know, I know), in
which the user chooses a person or creates a new one.  When this is done,
they hit a button, which checks to make sure that they have, in fact, done
so; if they have, it moves to the next form.  However, the next form (called
frmVolEffortGen), may or may not already be open.  If it is open, I want it
to get the new data from "tablepeople" and the focus.  If it is not open, I
want it to be opened, get the data, and have focus.  This is the code I have.

Private Sub Command28_Click()
'the "record the valiant effort of this volunteer" button

On Error GoTo Err_Command28_Click
  Dim stDocName As String
  Dim stLinkCriteria As String
  stDocName = "frmVolEffortGen"

'check to see that a name is actually selected
If IsNull(Me!LastName) Then
   MsgBox "Choose a volunteer, or create a new one."
   Cancel = True
   Me!Combo26.SetFocus
   'if frmVolEffortGen is loaded
   ElseIf CurrentProject.AllForms("frmVolEffortGen").IsLoaded Then
   'update the control with names
   Forms![frmVolEffortGen].Requery
   DoCmd.GoToRecord , , acNext, 1
   'following setfocus not working on that (or any) field
   'Forms![frmVolEffortGen]![EffortDate].SetFocus
  Else
   'open the form (@newrecord), set focus to a control
   DoCmd.OpenForm "frmVolEffortGen"
   DoCmd.GoToRecord , , acNewRec
   'DoCmd.GoToControl "EffortDate"
End If

The first IF condition works fine- it won't let me get past it if I forget to
choose a volunteer.  It also has no problem loading up "frmVolEffortGen" if
it is not open.  However, if "frmVolEffortGen"  is open, it gets neither the
focus nor the data. How can I fix that?

(Bonus question: whenever I try to shift focus to a control, Access tells me
it can't shift focus to that control.  Doesn't matter if they're text,
visible, enabled, combobox or subform- I've tried 'em all.  Any idea why?)
BonnieW - 01 Jun 2007 18:11 GMT
Still hoping for a response... if it helps, "tablepeople"  and
"frmVolEffortGen" are both bound forms, bound to different tables.

>I'm having a heck of a time with this form & form-switching.
>
[quoted text clipped - 41 lines]
>it can't shift focus to that control.  Doesn't matter if they're text,
>visible, enabled, combobox or subform- I've tried 'em all.  Any idea why?)
Marshall Barton - 01 Jun 2007 19:52 GMT
>Still hoping for a response... if it helps, "tablepeople"  and
>"frmVolEffortGen" are both bound forms, bound to different tables.
[quoted text clipped - 44 lines]
>>it can't shift focus to that control.  Doesn't matter if they're text,
>>visible, enabled, combobox or subform- I've tried 'em all.  Any idea why?)

I don't know, but try setting the focus to the other form
before the move next.  There may be an issue about some of
the DoCmd.GoTo... statements when it's not clear what has
the focus.

It may or may not be useful to use OpenForm whether the form
is open or not.  If it is already open, OpenForm just makes
it the active form.

Signature

Marsh
MVP [MS Access]

BonnieW - 01 Jun 2007 20:09 GMT
That actually worked great. Thanks! :) Now the forms switch; but
"frmVolEffortGen" doesn't update with the new volunteer information.  My new
code:
(the stuff with "Rem"  in front of it is from the last guy who tried to fix
it; the stuff that's remarked out with a ' is what I've tried or commented on)

Private Sub Command28_Click()
'the "record the valiant effort of this volunteer" button

On Error GoTo Err_Command28_Click
  Dim stDocName As String
  Dim stLinkCriteria As String
  stDocName = "frmVolEffortGen"
   
Rem  Check here if the volunteer effort form is already open (just change
Rem  the person for same task), otherwise open effort form as usual

Rem  If CurrentProject.AllForms("frmVolEffortGen").IsLoaded = True Then
Rem    DoCmd.Requery (Form_frmVolEffortGen![PeopleID])
Rem     from (Form_tablePeople![PeopleID])
Rem  End If
Rem this generates a "sub or function not defined" error

Rem If CurrentProject.AllForms("frmVolEffortGen").IsLoaded = True Then
Rem     DoCmd.Requery (Form_frmVolEffortGen![PeopleID])
Rem  End If
Rem this generates "there is no field named (current peopleid) in the current
record" error

Rem If CurrentProject.AllForms("frmVolEffortGen").IsLoaded = True Then
Rem     frmVolEffortGen![PeopleID].Requery
Rem    End If
Rem this generates "object required" error

'  If CurrentProject.AllForms("frmVolEffortGen").IsLoaded = True Then
'    DoCmd.Refresh frmVolEffortGen![PeopleID]
'  End If
'method or data member not found
   
'check to see that a name is actually selected
If IsNull(Me!LastName) Then
   MsgBox "Choose a volunteer, or create a new one."
   Cancel = True
   Me!Combo26.SetFocus
   'if frmVolEffortGen is loaded
   ElseIf CurrentProject.AllForms("frmVolEffortGen").IsLoaded Then
   'update the control with names
   Forms![frmVolEffortGen].Requery
   'following setfocus not working on that (or any) field
   'Forms![frmVolEffortGen]![EffortDate].SetFocus
   'but I still need to go to the form...
   Forms![frmVolEffortGen].SetFocus
   'then go to the next record
   DoCmd.GoToRecord , , acNext, 1
  Else
   'open the form (@newrecord), set focus to a control
   DoCmd.OpenForm "frmVolEffortGen"
   DoCmd.GoToRecord , , acNewRec
   'DoCmd.GoToControl "EffortDate"
End If
   

Exit_Command28_Click:
   Exit Sub

Err_Command28_Click:
   MsgBox Err.Description
   Resume Exit_Command28_Click
   
End Sub

>>Still hoping for a response... if it helps, "tablepeople"  and
>>"frmVolEffortGen" are both bound forms, bound to different tables.
[quoted text clipped - 10 lines]
>is open or not.  If it is already open, OpenForm just makes
>it the active form.
BonnieW - 01 Jun 2007 21:43 GMT
Solved it! Well, mostly.  Thanks. :)

>That actually worked great. Thanks! :) Now the forms switch; but
>"frmVolEffortGen" doesn't update with the new volunteer information.  My new
[quoted text clipped - 72 lines]
>>is open or not.  If it is already open, OpenForm just makes
>>it the active form.
Marshall Barton - 01 Jun 2007 23:59 GMT
Well, that's good to hear, especially since I still don't
really understand what's going on  ;-)
Signature

Marsh
MVP [MS Access]

>Solved it! Well, mostly.  Thanks. :)
>
[quoted text clipped - 74 lines]
>>>is open or not.  If it is already open, OpenForm just makes
>>>it the active form.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.