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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Analyze Form Toggle 3

Status
Not open for further replies.

puforee

Technical User
Oct 6, 2006
741
US
I have an Archive process that is started by a button on a form. However...I want a BIG warning when the button is depressed. The user must realize there are ramifications if they continue. The standard MsgBox is a little too tame for this situation. So, I built a WARNING form. At the bottom of the form is a toggle group. Yes continue archive = 1 and No =2

My code for the archive button...not on the warning form.

'DoCmd.OpenForm "frm_Archive_Warning", acNormal, "", "", acEdit, acNormal
'If [Forms]![frm_Archive_Warning]![Frame7] = 1 Then

I am not sure where to go from here. Will the code wait for the results of the Frame7. I do not have a default value for the frame so it all depends on which button is clicked. So, I don't want anything to happen until a button is clicked. If yes is clicked, I want to close the warning form and continue with the code below. If No is clicked I want to close the warning form and bypass the code below.

If Is_It_Archived = True Then
MsgBox "This record has already been archived"
Else
Dim Rev
Rev = Revision
'MsgBox Rev
DoCmd.SetWarnings WarningsOff
DoCmd.OpenQuery "qry_Archive_Main_Admin_To_ADB", acNormal, acEdit
DoCmd.OpenQuery "qry_Archive_Major", acNormal, acEdit
DoCmd.OpenQuery "qry_Archive_Minor", acNormal, acEdit
DoCmd.OpenQuery "qry_Archive_Media", acNormal, acEdit
DoCmd.SetWarnings WarningsOn
MsgBox "Revision " & Rev & " has been Archived" & Chr(10) & "Your document will now be set to the next revision #"
Me.Revision = Revision + 1
Me.LockCourse = 0
Me.RevisionDate = ""
Me.Model.SetFocus
Me.ArchiveCrsBtn.Enabled = False

End If
 
How to get a value from a form

Code:
Public Function getValueFromPopUp(formName As String, PopUpControlName As String) As Variant
  Dim frm As Access.Form
  DoCmd.OpenForm formName, , , , , acDialog
  'wait until form is closed or hidden
  If CurrentProject.AllForms(formName).IsLoaded Then
    Set frm = Forms(formName)
    getValueFromPopUp = frm.Controls(PopUpControlName).Value
    DoCmd.Close acForm, formName
  End If
End Function

to do this you need an ok and cancel button on the form.
The cancel button does a typical close
docmd.close acform, me.name
The OK button is the trick. You want to hide the form not close it
me.visible = false


example

dim rtn as integer
rtn = getValueFromPopUp("frm_Archive_Warning","Frame7")
if rtn = 1 then....

When you call the function the form pop open and code execution in the calling form stops until you close or hide the pop up form. Then it checks to see if the form is closed or hidden. If hidden it gets the value from the control.
 
MajP...Great...I will give it a try. It may be a while until I get to it. But I will provide feedback.
 
OK...I am working on this. So the Function looks like this: Does it look OK.

Public Function getValueFromPopUp(formName As String, PopUpControlName As String) As Variant
Dim frm As Access.Form
DoCmd.OpenForm "frm_Archive_Warning", acNormal, "", "", acEdit, acDialog
'wait until form is closed or hidden
If CurrentProject.AllForms("frm_Archive_Warning").IsLoaded Then
Set frm = Forms("frm_Archive_Warning")
getValueFromPopUp = frm.Controls(Frame7).Value
DoCmd.Close acForm, "frm_Archive_Warning"
End If
End Function

I also assigned the Close Form to the No (Cancel) button in Frame 7
I also assigned Visible False to the Yes button in Frame 7
Were these actions correct? There was no click event so I used mouse down.

Question? Does this code go at the start of my Archive button code? And does it look correct?
dim rtn as integer
rtn = getValueFromPopUp("frm_Archive_Warning","Frame7")
if rtn = 1 then....

Thanks again MajP

 
Yes it would go at the beginning. One mistake on my part.
The function would return null if you hit cancel/close
so I would need to trap the null. So modify to.
dim rtn as integer
rtn = NZ(getValueFromPopUp("frm_Archive_Warning","Frame7"),0)
if rtn = 1 then..
 
Thanks...I will try this tomorrow morning, and give you the results.
 
OK...having a bit of a problem with the code.

I was getting errors on this part...getValueFromPopUp = "frm_Archive_Warning.Frame7.Value" I adjusted as shown and the code got beyond this error. Is the code above good?

Now that it seems to pass the above code I get: Run-time error '13': Type mismatch.
Debug shows....
Dim rtn As Integer
rtn = Nz(getValueFromPopUp("frm_Archive_Warning", "Frame7"), 0) This line is highlighted in the debuggeer
If rtn = 1 Then
MsgBox "Archive worked"
Exit Sub
Else
MsgBox "Cancel Archive worked"
Exit Sub
I do have the Yes setting the form to me.visable = false.

I think we are almost there...a continued thanks for your help.
 
I'd use this function instead:
Code:
Public Function getValueFromPopUp(formName As String, PopUpControlName As String) As Variant
Dim frm As Access.Form
DoCmd.OpenForm formName, acNormal, "", "", acEdit, acDialog
If CurrentProject.AllForms(formName).IsLoaded Then
    Set frm = Forms(formName)
    getValueFromPopUp = frm.Controls(PopUpControlName).Value
    DoCmd.Close acForm, formName
End If
End Function

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
OK...PHV....your code worked...and I thank both of you for your assistance. Starts to all.

Not sure I understand all the code but I think I get the gist.

Now I will tie everything together.
 
@PHV,
Not sure I understand why that fixes it or why the original would not work for the user? Aren't those all optional and the defaults? I cannot recreate the problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top