![]() |
|
|
Welcome to the { mindfrost82.com } forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
Waiting for subroutine to finish
I want to stop exectution of my code until another routine had finished
This is not the actual code I'm trying to create, but it is a sample of how I want the code to halt. Something like this: Sub DoChanges Dim intCount as integer For intCount = 1 to 10000 Next intCount DoCmd.Open Form "MyForm", , , ,acDialog End Sub Sub BigCalendar DoChanges ' I'd like to halt here until timing has finished MsgBox "Done" End Sub Is it possible to stop the code? |
|
|||
|
Re: Waiting for subroutine to finish
VBA is not multi-threaded, so your code will work as is.
When you call DoChanges, the MsgBox won't show until DoChanges completes. When you open MyForm in dialog view, that pauses the rountine. So DoChanges DoChanges won't complete until you close the dialog, and therefore it won't pass control back to BigCalendar, and so the MsgBox won't dispaly until after the dialog form closes. -- Allen Browne - Microsoft MVP. Perth, Western Australia Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. "Dominic Vella" <dominic.vella@optusnet.com.au> wrote in message news:983E6572-7152-446C-816F-D8A3283D5B94@microsoft.com... >I want to stop exectution of my code until another routine had finished > This is not the actual code I'm trying to create, but it is a sample of > how I want the code to halt. > Something like this: > > Sub DoChanges > Dim intCount as integer > For intCount = 1 to 10000 > Next intCount > DoCmd.Open Form "MyForm", , , ,acDialog > End Sub > > Sub BigCalendar > DoChanges > ' I'd like to halt here until timing has finished > MsgBox "Done" > End Sub > > > Is it possible to stop the code? |
|
|||
|
Re: Waiting for subroutine to finish
After you call dochanges from bigcalendar, the code in bigcalendar will halt
until the form closes because you're using the acdialog argument (but you need 5 commas between arguments, not 4). Do you want to let Access sit there for a while longer before the msgbox pops up? You could use the sleep api function. Put the api declaration at the top of the module: Private Declare Sub_ Sleep Lib "kernel32" _ (ByVal dwMS As Long) and then in your procedure: Sub BigCalendar DoChanges Sleep 5000 'sleep 5 seconds MsgBox "Done" End Sub Chris Microsoft MVP Dominic Vella wrote: >I want to stop exectution of my code until another routine had finished >This is not the actual code I'm trying to create, but it is a sample of how >I want the code to halt. >Something like this: > >Sub DoChanges > Dim intCount as integer > For intCount = 1 to 10000 > Next intCount > DoCmd.Open Form "MyForm", , , ,acDialog >End Sub > >Sub BigCalendar > DoChanges > ' I'd like to halt here until timing has finished > MsgBox "Done" >End Sub > >Is it possible to stop the code? -- Message posted via http://www.accessmonster.com |
|
|||
|
Re: Waiting for subroutine to finish
As Allen has mentioned, your code will run as is. You do not need to wait
unless you are using an outside process. However, your wait code is processor dependent. Faster processors will run it faster than slower processors. Instead use the computer's clock which should tick off the same time on any machine (give or take a few milliseconds a day). The following code will delay as long as you want for an outside process. It will stop your current code until the time is up: http://www.datastrat.com/Code/Delay.txt -- Arvin Meyer, MCP, MVP http://www.datastrat.com http://www.mvps.org/access http://www.accessmvp.com "Dominic Vella" <dominic.vella@optusnet.com.au> wrote in message news:983E6572-7152-446C-816F-D8A3283D5B94@microsoft.com... >I want to stop exectution of my code until another routine had finished > This is not the actual code I'm trying to create, but it is a sample of > how I want the code to halt. > Something like this: > > Sub DoChanges > Dim intCount as integer > For intCount = 1 to 10000 > Next intCount > DoCmd.Open Form "MyForm", , , ,acDialog > End Sub > > Sub BigCalendar > DoChanges > ' I'd like to halt here until timing has finished > MsgBox "Done" > End Sub > > > Is it possible to stop the code? |
|
|||
|
Re: Waiting for subroutine to finish
Well, I'm as stumped as you then, so I'll give a clearer picture of what I'm
doing. '== In form1 I've got a routine which calls a module routine. Private Sub cmdDetailEdit_Click() EditSingle("Item Details", "tblItems", "[item_id]=" & Me.lstDetail, "item_detail", "Item Heading") Me.lstDetail.Requery End Sub '== In Module1 the routine designs a template form Public Sub EditSingle(strFormCaption As String, strTable As String, strCriteria As String, strTextField As String, strTextCaption As String) DoCmd.OpenForm "fdlgTemplate", acNormal With Forms("fdlgTemplate") .Caption = strFormCaption .RecordSource = "SELECT " & strTable & ".* FROM " & strTable & " WHERE " & strCriteria & ";" .lblHeading.Caption = strFormCaption .txtField.ControlSource = strTextField .lblField.Caption = strTextCaption End With DoCmd.OpenForm "fdlgTemplate", , , strCriteria, , acDialog End Sub The problem is the form1.lstDetail requery's before fdlgTemplate has finished. Can anyone explain or help? Thanks Dominic "Allen Browne" <AllenBrowne@SeeSig.Invalid> wrote in message news:%23BGECxlBJHA.1980@TK2MSFTNGP03.phx.gbl... > VBA is not multi-threaded, so your code will work as is. > > When you call DoChanges, the MsgBox won't show until DoChanges completes. > > When you open MyForm in dialog view, that pauses the rountine. So > DoChanges DoChanges won't complete until you close the dialog, and > therefore it won't pass control back to BigCalendar, and so the MsgBox > won't dispaly until after the dialog form closes. > > -- > Allen Browne - Microsoft MVP. Perth, Western Australia > Tips for Access users - http://allenbrowne.com/tips.html > Reply to group, rather than allenbrowne at mvps dot org. > > "Dominic Vella" <dominic.vella@optusnet.com.au> wrote in message > news:983E6572-7152-446C-816F-D8A3283D5B94@microsoft.com... >>I want to stop exectution of my code until another routine had finished >> This is not the actual code I'm trying to create, but it is a sample of >> how I want the code to halt. >> Something like this: >> >> Sub DoChanges >> Dim intCount as integer >> For intCount = 1 to 10000 >> Next intCount >> DoCmd.Open Form "MyForm", , , ,acDialog >> End Sub >> >> Sub BigCalendar >> DoChanges >> ' I'd like to halt here until timing has finished >> MsgBox "Done" >> End Sub >> >> >> Is it possible to stop the code? > |
|
|||
|
Re: Waiting for subroutine to finish
But fdlgTemplate is not opened in dialog mode.
Trying to open it in dialog mode when it's already open is not going to be useful. -- Allen Browne - Microsoft MVP. Perth, Western Australia Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. "Dominic Vella" <dominic.vella@optusnet.com.au> wrote in message news:BF3070AD-1D23-41D9-AF40-F6BE10FC12EB@microsoft.com... > Well, I'm as stumped as you then, so I'll give a clearer picture of what > I'm doing. > > '== In form1 I've got a routine which calls a module routine. > Private Sub cmdDetailEdit_Click() > EditSingle("Item Details", "tblItems", "[item_id]=" & Me.lstDetail, > "item_detail", "Item Heading") > Me.lstDetail.Requery > End Sub > > '== In Module1 the routine designs a template form > Public Sub EditSingle(strFormCaption As String, strTable As String, > strCriteria As String, strTextField As String, strTextCaption As String) > DoCmd.OpenForm "fdlgTemplate", acNormal '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > With Forms("fdlgTemplate") > .Caption = strFormCaption > .RecordSource = "SELECT " & strTable & ".* FROM " & strTable & " > WHERE " & strCriteria & ";" > .lblHeading.Caption = strFormCaption > .txtField.ControlSource = strTextField > .lblField.Caption = strTextCaption > End With > DoCmd.OpenForm "fdlgTemplate", , , strCriteria, , acDialog > End Sub > > The problem is the form1.lstDetail requery's before fdlgTemplate has > finished. Can anyone explain or help? |
|
|||
|
Re: Waiting for subroutine to finish
I would normally agree, however I need to open the form in normal mode so
that I can change the forms Record Source, change the Label caption and change the text box Control Source. I then after the form is closed I want the list to refresh. Well, I figure my last option then is to pass the reference to the list to the Dialog form too so that the Dialog form will do the refreshing when it closes. Does that sound like the best idea? By the way, thanks for your input. I appreciate it. Dom "Allen Browne" <AllenBrowne@SeeSig.Invalid> wrote in message news:uYhha2nBJHA.3392@TK2MSFTNGP03.phx.gbl... > But fdlgTemplate is not opened in dialog mode. > > Trying to open it in dialog mode when it's already open is not going to be > useful. > > -- > Allen Browne - Microsoft MVP. Perth, Western Australia > Tips for Access users - http://allenbrowne.com/tips.html > Reply to group, rather than allenbrowne at mvps dot org. > > "Dominic Vella" <dominic.vella@optusnet.com.au> wrote in message > news:BF3070AD-1D23-41D9-AF40-F6BE10FC12EB@microsoft.com... >> Well, I'm as stumped as you then, so I'll give a clearer picture of what >> I'm doing. >> >> '== In form1 I've got a routine which calls a module routine. >> Private Sub cmdDetailEdit_Click() >> EditSingle("Item Details", "tblItems", "[item_id]=" & Me.lstDetail, >> "item_detail", "Item Heading") >> Me.lstDetail.Requery >> End Sub >> >> '== In Module1 the routine designs a template form >> Public Sub EditSingle(strFormCaption As String, strTable As String, >> strCriteria As String, strTextField As String, strTextCaption As String) >> DoCmd.OpenForm "fdlgTemplate", acNormal > > '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > >> With Forms("fdlgTemplate") >> .Caption = strFormCaption >> .RecordSource = "SELECT " & strTable & ".* FROM " & strTable & " >> WHERE " & strCriteria & ";" >> .lblHeading.Caption = strFormCaption >> .txtField.ControlSource = strTextField >> .lblField.Caption = strTextCaption >> End With >> DoCmd.OpenForm "fdlgTemplate", , , strCriteria, , acDialog >> End Sub >> >> The problem is the form1.lstDetail requery's before fdlgTemplate has >> finished. Can anyone explain or help? > |
![]() |
|
| Thread Tools | Search this Thread |
| Display Modes | |
|
|