Full Version: By-Pass a Procedure
UtterAccess Forums > Microsoft® Access > Access Forms
quest4
Good morning. A quick question, I would like to open a form from another form, but I need to by-pass the new form's OnOpen event. Can this be done? Thank you in advance for any opeions offered here. shrug.gif
khaos
You could use the open args parameter in the on open call. Use that in the on open of the 2nd form and with an if loop bypass the code if needed.
TH
Ken
quest4
Thank you for the response, Ken. You wouldn't happen to have a quick example would you. Sounds interesting, with possiblities. My form's OnOpen event creates new records or calls entered existing ones and I would like to get around it or by-pass it, so I could open it from a search form, in its' OnClick event. Thank you again for the help.
dannyseager
I assume you want to do this because newform is usually opened from form1 but in some cases it's loaded from form2 but in the on open of the newform it refers to form1 and you want these ignored if it's opened from form2?
You could alter the on open procedure to check to see if form1 is open so if it's not it ignores the code it needs to..
If CurrentProject.AllForms("form1").IsLoaded = True Then
normal open code assuming that form 1 is loaded
else
new code if it's opened from form 2
end if
khaos
Just look up open args in the vba help. Great example there.
TH
Ken
quest4
Thank you both for the responses. Danny, I am trying to open the main form from one of two different search forms, but I don't want the main forms OnOpen event to run, because the procedure will ask if this is a new record yes/no and from there the whole OnOpen procedure kicks in. I am not even sure if the example would work that way. Ken, I will definately look into vb Help, what a surprise, Help actually helping for a change. Thank you both again for the help.
khaos
You're welcome, glad to help. The vba help has great info it's just not easy to find sometimes. I have better luck putting my cursor on a keyword and hitting f1, this returns different and better results than typing it into the help search box.
en
quest4
Thank you for the tip I will have to try it. I am going to start to build a procedure and see if it will work. Thanks.
quest4
I have been trying a few things now and I can not get by the OnOpen event of the main form. This was what I have been playing with:
Dim stDocName As String
'Dim stLinkCriteria As String
stDocName = "frmQualityControlAction"
'stLinkCriteria = "[QCANo]=" & Me![QCANo]
DoCmd.OpenForm stDocName, , , stLinkCriteria
If SysCmd(acSysCmdGetObjectState, ACForm, "frmQualityControlAction") Then
Forms("frmQualityControlAction")("QCANo").Value = Me("QCANo").Value
DoCmd.Close ACForm, "frmPartNoLookUp"
End If
The If SysCmd works great inside the main form, I am using it as a find QCANo and load it into the main form. The trick is to Open the main form and by-passing the OnOpen event. Right now, The main form is opening, but the yes/no of the OnOpen procedure is poping up. Is there any modification I can do to this to get around OnOpen? Thank you again in advance.
quest4
I made a change to this but it is erroring out:
If Not IsNull(Forms!frmQualityControlAction.OpenArgs) Then
Dim strQCA As String
strQCA = Forms!frmQualityControlAction.OpenArgs
Dim rs As Recordset
Set rs = Forms!frmQualityControlActionRecordsetClone
rs.FindFirst "QCANo = '" & strQCA & "'"
If Not rs.NoMatch Then
Me.Bookmark = rs.Bookmark
End If
End If
The error is: Method or Data Member not Found
The debugger hi-lites the FindFirst. Any suggestions? Thanks. confused.gif confused.gif
khaos
Change this
im rs As Recordset
to
Dim rs As ADODB.Recordset
and tell me what you get.
quest4
Same thing same error message.
quest4
This may make things easier. It is striped but everything opens.
khaos
Which form do I need to look at?
quest4
Ops, sorry about that. I am working on the OnClick event of the frmPartNoQCALookUp, the OnClick is in the subform, fsubPartNoQCALookup. When one of the QCANo numbers is click the other form,frmQualityControlAction, should open and theat record should be in it. Am it being clear enough? Thank you again for the help.
khaos
This code should fire from the subform "fsubPartNoQCALookup"
tDocName = "frmQualityControlAction"
stLinkCriteria = "[QCANo]=" & Me![QCANo]
DoCmd.OpenForm stDocName, , , stLinkCriteria
this code should be in the on open event of form "frmQualityControlAction"
If Not IsNull(me.OpenArgs) Then
Dim strQCA As String
strQCA = me.OpenArgs
Dim rs As ADODB.Recordset
Set rs = Forms!frmQualityControlActionRecordsetClone
rs.FindFirst "QCANo = '" & strQCA & "'"
If Not rs.NoMatch Then
Me.Bookmark = rs.Bookmark
End If
End If
Can't test it as I'm missing some references you have.
HTH
Ken
quest4
Thank you so very much Ken. I see I had my code in the wrong place. One major question, will this interfer with the OnOpen event that is already in the form, frmQualityControlAction? That is what is opening the form normally, and that is the main form in the dbase. I would hate to scramble that up. Thank you again for all of the help, I will try this in the morning.
khaos
Just do this
If Not IsNull(me.OpenArgs) Then
Dim strQCA As String
strQCA = me.OpenArgs
Dim rs As ADODB.Recordset
Set rs = Forms!frmQualityControlActionRecordsetClone
rs.FindFirst "QCANo = '" & strQCA & "'"
If Not rs.NoMatch Then
Me.Bookmark = rs.Bookmark
End If
else
'code originally in the on open event
End If
HTH
Ken
quest4
Good morning, Ken. Same error, Method or Data member not Found. Then the debugger pops up its' ugly head and hi-lites the word FindFirst. Same as before. I did try MoveFirst, to see what would happen, it error out also, but different error. Dumb question time, isn't FindFirst DAO? Or does it work in both? Also, I did change it to DAO, But I got the YES/NO pop-up, no by-pass. Thank you again for all of your help and time. shrug.gif
Edited by: quest4 on Wed Oct 20 8:38:12 EDT 2004.
khaos
Change this
im rs As ADODB.Recordset
to
Dim rs As Object
That may clear it up right away.
Ken
quest4
Made the change. No error, only the YES/NO pop-up from the original OnOpen event. Here is what I have now:
If Not IsNull(Me.OpenArgs) Then
'Dim rs As ADODB.Recordset
Dim rs As Object
Dim strQCA As String
Set rs = Forms!frmQualityControlAction.RecordsetClone
strQCA = Me.OpenArgs
rs.FindFirst "QCANo = '" & strQCA & "'"
If Not rs.NoMatch Then
Me.Bookmark = rs.Bookmark
End If
Else
Dim myQNumber As String
Response = MsgBox("Would You Like to Issue a New Quality Control Action", vbYesNo + vbDefaultButton2, "New?")
If Response = vbYes Then
DoCmd.GoToRecord , , acNewRec
Forms!frmQualityControlAction.QCANo = NextIDNumber()
ElseIf Response = vbNo Then
myQNumber = InputBox(Prompt:="What is the Quality Control Action No?")
If myQNumber = Empty Then
MsgBox Prompt:="You Did NOT Enter a Quality Control Action No."
DoCmd.Close
'DoCmd.GoToRecord , , acFirst
Else
Me.RecordsetClone.FindFirst "[QCANo]=" & myQNumber
If Me.RecordsetClone.NoMatch Then
MsgBox "Couldn't Find Quality Control Action No." & myQNumber
DoCmd.Close
Else
Me.Bookmark = Me.RecordsetClone.Bookmark
End If
End If
End If
End If
DoCmd.Maximize
So close and yet so far away. What is wring with this? Need coffee. Thanks. giveup.gif
khaos
Made some slight changes, what is wrong with the yes/no code?
CODE

If Not IsNull(Me.OpenArgs) Then
    'Dim rs As ADODB.Recordset
    Dim rs As Object
    Dim strQCA As String
    
    Set rs = Me.RecordsetClone
    
    strQCA = Me.OpenArgs
    rs.FindFirst "QCANo = '" & strQCA & "'"
    If Not rs.NoMatch Then
        Me.Bookmark = rs.Bookmark
    End If
Else
    Dim myQNumber As String
    Dim Response As VbMsgBoxResult
    Response = MsgBox("Would You Like to Issue a New Quality Control Action", vbYesNo + vbDefaultButton2, "New?")
    If Response = vbYes Then
        DoCmd.GoToRecord , , acNewRec
        Me.QCANo = NextIDNumber()
    Else
        myQNumber = InputBox(Prompt:="What is the Quality Control Action No?")
        If myQNumber = Empty Then
            MsgBox Prompt:="You Did NOT Enter a Quality Control Action No."
            DoCmd.Close
            'DoCmd.GoToRecord , , acFirst
        Else
            Me.RecordsetClone.FindFirst "[QCANo]=" & myQNumber
            If Me.RecordsetClone.NoMatch Then
                MsgBox "Couldn't Find Quality Control Action No." & myQNumber
                DoCmd.Close
            Else
                Me.Bookmark = Me.RecordsetClone.Bookmark
            End If
        End If
    End If
End If
DoCmd.Maximize
quest4
I changed the code. Same thing. Instead of the the form,frmQualityControlAction opening with the selected record from the form, frmPartNoQCALookUp, I get the YES/NO pop-up. This is what I was hoping to get around. Thank you again.
khaos
Sorry I missed this, just assumed it was right without checking if your openargs was in the proper parameter
oCmd.OpenForm stDocName, , , ,,,stLinkCriteria
HTH
Ken
quest4
I made the change. Data Type Mismatch in Criteria Expression. When I open the debugger our old friend the FindFirst is hi-lited. I take it that the commas move where the criteria is execxuted. Thanks.
khaos
Change
s.FindFirst "QCANo = '" & strQCA & "'"
to
rs.FindFirst strQCA
HTH
Ken
quest4
After, I am sure much fustration, SUCCESS. I finally got a dumb query to do something besides just sit there and look pretty. Thank you very much for all of your time and assistnace, it is deeply appreciated. yayhandclap.gif yayhandclap.gif yayhandclap.gif
khaos
You're welcome, glad to help.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.