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.

Go Back   { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Microsoft > MS Office > Access

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-25-2008, 03:08 AM
Dominic Vella
 
Posts: n/a
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?

Reply With Quote
  #2 (permalink)  
Old 08-25-2008, 03:42 AM
Allen Browne
 
Posts: n/a
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?


Reply With Quote
  #3 (permalink)  
Old 08-25-2008, 03:45 AM
Chris O'C via AccessMonster.com
 
Posts: n/a
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

Reply With Quote
  #4 (permalink)  
Old 08-25-2008, 04:18 AM
Arvin Meyer [MVP]
 
Posts: n/a
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?



Reply With Quote
  #5 (permalink)  
Old 08-25-2008, 06:24 AM
Dominic Vella
 
Posts: n/a
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?

>


Reply With Quote
  #6 (permalink)  
Old 08-25-2008, 07:41 AM
Allen Browne
 
Posts: n/a
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?


Reply With Quote
  #7 (permalink)  
Old 08-25-2008, 08:15 AM
Dominic Vella
 
Posts: n/a
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?

>


Reply With Quote
Reply

  { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Microsoft > MS Office > Access


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 04:54 PM.


Powered by vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
© 1999-2008 mindfrost82.com v11.0


Sponsors:
Company Reports | Mortgage Calculator | Car Finance | Power Rangers | Credit Cards



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114