Change VB Code to Close

  • Thread starter Thread starter Bob
  • Start date Start date
B

Bob

I want to change this code slightly so if there is no data in The combo Box
OwnerInfo that the form will not save on closing
Private Sub cmdClose_Click()
If Me.OpenArgs = "ActiveHorses" Then
Me.Requery
Forms!frmActiveHorses.Visible = True
Forms!frmActiveHorses!cbHorseName.Requery
End If
subSetValues
DoCmd.Close acForm, Me.Name
End Sub

Thanks in advance.........Bob Vance
 
if what you said is what you meant -- the FORM will not save...
'~~~~~~~~~~~~~~~~`
if isnull(me.OwnerInfo) then
DoCmd.Close acForm, Me.Name, acSaveNo
else
DoCmd.Close acForm, Me.Name, acSaveYes
end if
'~~~~~~~~~~~~~~~

if what you meant is that the RECORD will not save...
'~~~~~~~~~~~~~~~~`
if isnull(me.OwnerInfo) then
if me.dirty then
me.undo
end if
end if

DoCmd.Close acForm, Me.Name
'~~~~~~~~~~~~~~~

Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 
Keep getting a compile error after Me.
The combo box is in SubHorseDetails on the form does that make a
difference....Thanx Bob
 
Compile error
Method or data member not found!

strive4peace said:
if what you said is what you meant -- the FORM will not save...
'~~~~~~~~~~~~~~~~`
if isnull(me.OwnerInfo) then
DoCmd.Close acForm, Me.Name, acSaveNo
else
DoCmd.Close acForm, Me.Name, acSaveYes
end if
'~~~~~~~~~~~~~~~

if what you meant is that the RECORD will not save...
'~~~~~~~~~~~~~~~~`
if isnull(me.OwnerInfo) then
if me.dirty then
me.undo
end if
end if

DoCmd.Close acForm, Me.Name
'~~~~~~~~~~~~~~~

Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 
Hi Bob,

"The combo box is in SubHorseDetails on the form does that
make a difference...."

yes!

if isnull(me.SubHorseDetails.form.OwnerInfo) then



Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 
Hi Bob,

After "Me.", you must use the NAME property for the subform
control, not the SourceObject property. After that, you
must have ".form" to specify your want a control on the
subform as opposed to the container itself, then, again, you
must use the NAME property of the OwnerInfo control, not the
ControlSource property

Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 
Thanks Crystal for your help, Got it

Private Sub cmdClose_Click()
If IsNull(Me.subHorseDetailsChild.Form.OwnerID) Then
If Me.Dirty Then
Me.Undo
End If
End If

DoCmd.Close acForm, Me.Name

End
 
Crystal can it be change so if there is nothing in OwnerID it will not
close! Regards Bob
 
Hi Bob,

try this:

'~~~~~~~~~~~~~~~~~
Private Sub cmdClose_Click()

If IsNull(Me.subHorseDetailsChild.Form.OwnerID) Then

'if you want to undo the sub form
If Me.subHorseDetailsChild.Form.Dirty Then
Me.subHorseDetailsChild.Form.Undo
End If

'if you want to undo the main form
if me.dirty then
me.undo
endif

End If

DoCmd.Close acForm, Me.Name, acSaveNo

end sub
'~~~~~~~~~~~~~~~~~

Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 
Thanks Crystal
I deletes the record ID if there is OwnerID is empty
But is it possible that nothing happens when you click Close_Click()
if OwnerID has no data Just saves re-entering data because you forgot to put
the OwnerID in
Thanks for your Help...........Bob
 
you're welcome, Bob ... so did you have another question?

Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 
Is it Possible the Close_Click Button will not work unless OwnerId has Data
in it?
Seems a shame you enter data in other fields and forget to put it in OwnerID
then you lose it and have to re type again
Thanks Crystal
 
Hi bob,

Sounds like what you need is to use the BeforeUpdate
event... this is where data validation is done -- on the
subform BeforeUpdate event -- where the control is...

'~~~~~~~~~~~~~~~~~~ form BeforeUpdate
if isnull(me.ownerID) then
msgbox "You must enter OwnerID" _
,,"Missing Data"
CANCEL = true
end if
'~~~~~~~~~~~~~~~~~~

Undo will, of course, undo all the changes and that is not
what it appears you want to do

Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 
Thanks Crystal
Couldn't get that last code to work I will just stick with the deleting
code........Thank you very much for your help....Bob
 
you're welcome, Bob ;) happy to help

Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 
Back
Top