Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

docmd.close prob

Status
Not open for further replies.

nevstic

Instructor
Jul 30, 2002
98
GB
Good afternoon all
I have put the following code inmy lost focus event
and it thows out an error saying "that it cannot execute this type of etc"

Private Sub close_main_LostFocus()
If IsNull(Me!List90) Or IsNull(Me!StaffMember) Then
Dim IntResponse As Integer
IntResponse = MsgBox("Exit without saving record ?", vbYesNo + vbDefaultButton1, "EXIT ?")

If IntResponse = vbYes Then
DoCmd.Close
Else
another bit etc
End If
End If
End Sub

Could you please tell me why?
and also a way round the problem.

Thanks very much

Nick
 
What type of object is close_main ?

& why are you using On_LostFocus

Where has the focus gone to once close_main has lost it ?

What code is running in responce to the Got_Focus ( or ssimilar ) in the next object ?



G LS
 
Thanks for your quick response GLS
the object is a close button on a form, and I think I am beginning to see .....just by your questions !

I just want to close the form if the "if " is true or else
go back to an unused or null control on the form.
but I need to ask the question, hence the msgbox.

Where oh where am I ?

Thanks a lot
Gls
your help most appreciated.

Best regards
Nick
 
Use the Click event of the button and you'll have more luck.

Also, it's best to indent your code, to make it a bit easier to read:

If yadda then
If Yoda then
'some stuff
else
'some other stuff
end if
end if

And if you post the full text of the error message, that will help a lot.

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developer's section of the site for some helpful fundamentals.
 
What if the user clicks the close on the form? What happens then? Did you disable it? Life's a journey enjoy the ride...

jazzz
 
The previous poster has a good point. I would actually move that if structure to the Close or Unload event, whichever has the cancel parameter in it, so that you can cancel the event no matter how the user tries to close the form.

Then you command button would just close the form--as it will be cancelled if need be.

jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developer's section of the site for some helpful fundamentals.
 
Ok thanks everyone
I need a litle time to digest all of this ,

I will return
Thanks again
Rgds
Nick
 
Hello again
would it be poss to refer to any ctrl on the form
without actually using the name
like

If isnull [anyctrl] then
set focus to that ctrl

many thanks again

rgds
Nick
 
Nope. Gotta do that in the control itself. You can make a function to run your code and put =MyFunction() in the property sheet for the event you want in as many controls as you want (and you can multi select the controls to do this in one action). And check into screen.ActiveControl.

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developer's section of the site for some helpful fundamentals.
 
ok thanks
I may be back as I have never written a function before

thanks again Jeremy
have a nice w/e
rgds
nick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top