Hi
First of all apologies for posting so much code but this is rather involved
and I am totally stumped. Basically I have a main form (Staff Batch
SMS/E-Mail) which calls a function (SendSMS) in a module with in turn calls
a form (frmInet) which contains an ms internet control (Inet1). Problem is
that once the function Send SMS returns and the code tries to close the main
form a 'Runtime error 2486: You can't carry out this action at present time'
error occurs. No matter what I try, I get no choice but to end task access
to come out. Any ideas what is causing the form to not close after the
SendSMS function is executed?
Thanks
Regards
= Code Below =============== =============== =========
'= Code in calling form 'Staff Batch SMS/E-Mail' =============== ====
Option Compare Database
Option Explicit
Private Sub Command41_Click ()
Dim strReturn As String
If SendSMS(PhoneSt , Left(Me.Descrip tion, 160), strReturn, True) = 1 Then
DoCmd.Close acForm, "Staff Batch SMS/E-Mail" '<== Error on this line:
End If
End Sub
'= Code in Module SMS =============== =============== =====
Public Function SendSMS(ByVal strMobile As String, ByVal strMessage As
String, Optional strReturn As String, Optional IsHourGlass As Boolean =
False) As Byte
On Error GoTo ErrSMSSend
Dim objInet As Inet
Dim strHeaders As String
Dim strData As String
Dim datStart As Date
Dim booTimeOut
Dim intSendSMS As Integer
Dim strUserName As String
Dim strPassword As String
Dim strURL As String
Dim strHeader
'Get the passwords etc to use
strUserName = SMSUser
strPassword = SMSPassword
strURL = SMSUrl
strHeader = IIf(IsNull(Form s![Staff Batch SMS/E-Mail]![Sender]), SMSHeader,
Forms![Staff Batch SMS/E-Mail]![Sender])
'Send the message
DoCmd.OpenForm "frmInet", , , , , acHidden
strHeaders = "Content-Type: application/x-www-form-urlencoded" & vbCrLf
Forms!frmInet!I net1.Execute strURL, "POST", strData, strHeaders
'Look for return code or wait for time out and show error
datStart = Now
Do
DoEvents
booTimeOut = (DateDiff("n", datStart, Now()) >= 0.5) 'Set for 2 minute
timeout, adjust value after >= to max minutes to wait
Loop Until Forms!frmInet.C ontrolState = 12 Or booTimeOut
If booTimeOut Then
intSendSMS = 10
strReturn = "Timeout"
Else
strReturn = Trim(Replace(Re place(Replace(F orms!frmInet.Pa geReturn, Chr(9),
""), Chr(10), ""), Chr(13), ""))
If IsNumeric(Forms !frmInet.PageRe turn) Then
intSendSMS = CInt(Forms!frmI net.PageReturn)
Else
intSendSMS = 11
End If
End If
If intSendSMS = 0 Then
SendSMS = 1
Else
SendSMS = intSendSMS
End If
Select Case intSendSMS
Case 0
MsgBox "SMS Message sent.", vbInformation
Case Else
MsgBox "There was an unexpected problem sending the message, this may
not have been sent. Return code = " & intSendSMS & ". Please pass this code
on to system administrator." , vbInformation
End Select
ExitSMSSend:
On Error Resume Next
DoCmd.Close acForm, "frmInet"
Exit Function
ErrSMSSend:
MsgBox "Error " & Err.Number & ": " & Err.Description
SendSMS = 20
Resume ExitSMSSend
End Function
'Code in frmInet which contains an ms internet control inet1
Option Explicit
Dim intState As Integer
Dim strPageReturn
Private Sub Inet1_StateChan ged(ByVal State As Integer)
On Error GoTo ErrInet1_StateC hanged
' Retrieve server response using the GetChunk
' method when State = 12.
Dim vtData As Variant
Dim strData As String
Dim bDone As Boolean: bDone = False
intState = State
Select Case State
' ... Other cases not shown.
Case icError ' 11
' In case of error, return ResponseCode and
' ResponseInfo.
vtData = Inet1.ResponseC ode & ":" & _
Inet1.ResponseI nfo
strPageReturn = vtData
Case icResponseCompl eted ' 12
' Get first chunk.
vtData = Inet1.GetChunk( 1024, icString)
DoEvents
Do While Not bDone
strData = strData & vtData
' Get next chunk.
vtData = Inet1.GetChunk( 1024, icString)
DoEvents
If Len(vtData) = 0 Then
bDone = True
End If
Loop
Dim a, b
a = InStr(strData, "<Response> ") + 10
b = InStr(strData, "</Response>")
strPageReturn = Mid(strData, a, 2)
Debug.Print strPageReturn, strData
' MsgBox strPageReturn, , "Return data"
End Select
ExitInet1_State Changed:
Exit Sub
ErrInet1_StateC hanged:
MsgBox "Error " & Err.Number & ": " & Err.Description
Resume ExitInet1_State Changed
End Sub
Property Get ControlState() As Byte
ControlState = intState
End Property
Property Get PageReturn() As String
PageReturn = strPageReturn
End Property 1 2246
Nothing really obvious, John.
There is an object variable that you are not dereferencing: objInet .
There is also a DoEvents, which could possibly affect the timing of when
Access attempts to close the form, or retrigger the same routine again.
Even though you do not have any dependencies on the form after the DoEvents,
Access may not know this, and may believe that the form is still needed.
--
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.
"John" <jo**@nospam.in fovis.co.uk> wrote in message
news:40******** *************** @news.dial.pipe x.com... First of all apologies for posting so much code but this is rather
involved and I am totally stumped. Basically I have a main form (Staff Batch SMS/E-Mail) which calls a function (SendSMS) in a module with in turn
calls a form (frmInet) which contains an ms internet control (Inet1). Problem is that once the function Send SMS returns and the code tries to close the
main form a 'Runtime error 2486: You can't carry out this action at present
time' error occurs. No matter what I try, I get no choice but to end task access to come out. Any ideas what is causing the form to not close after the SendSMS function is executed?
Thanks
Regards
= Code Below =============== =============== =========
'= Code in calling form 'Staff Batch SMS/E-Mail' =============== ==== Option Compare Database Option Explicit
Private Sub Command41_Click () Dim strReturn As String
If SendSMS(PhoneSt , Left(Me.Descrip tion, 160), strReturn, True) = 1 Then DoCmd.Close acForm, "Staff Batch SMS/E-Mail" '<== Error on this line: End If End Sub
'= Code in Module SMS =============== =============== ===== Public Function SendSMS(ByVal strMobile As String, ByVal strMessage As String, Optional strReturn As String, Optional IsHourGlass As Boolean = False) As Byte
On Error GoTo ErrSMSSend Dim objInet As Inet Dim strHeaders As String Dim strData As String Dim datStart As Date Dim booTimeOut Dim intSendSMS As Integer Dim strUserName As String Dim strPassword As String Dim strURL As String Dim strHeader
'Get the passwords etc to use strUserName = SMSUser strPassword = SMSPassword strURL = SMSUrl strHeader = IIf(IsNull(Form s![Staff Batch SMS/E-Mail]![Sender]),
SMSHeader, Forms![Staff Batch SMS/E-Mail]![Sender])
'Send the message DoCmd.OpenForm "frmInet", , , , , acHidden
strHeaders = "Content-Type: application/x-www-form-urlencoded" & vbCrLf
Forms!frmInet!I net1.Execute strURL, "POST", strData, strHeaders
'Look for return code or wait for time out and show error datStart = Now Do DoEvents booTimeOut = (DateDiff("n", datStart, Now()) >= 0.5) 'Set for 2 minute timeout, adjust value after >= to max minutes to wait Loop Until Forms!frmInet.C ontrolState = 12 Or booTimeOut If booTimeOut Then intSendSMS = 10 strReturn = "Timeout" Else strReturn = Trim(Replace(Re place(Replace(F orms!frmInet.Pa geReturn,
Chr(9), ""), Chr(10), ""), Chr(13), "")) If IsNumeric(Forms !frmInet.PageRe turn) Then intSendSMS = CInt(Forms!frmI net.PageReturn) Else intSendSMS = 11 End If End If
If intSendSMS = 0 Then SendSMS = 1 Else SendSMS = intSendSMS End If
Select Case intSendSMS Case 0 MsgBox "SMS Message sent.", vbInformation Case Else MsgBox "There was an unexpected problem sending the message, this may not have been sent. Return code = " & intSendSMS & ". Please pass this
code on to system administrator." , vbInformation End Select
ExitSMSSend: On Error Resume Next DoCmd.Close acForm, "frmInet" Exit Function
ErrSMSSend: MsgBox "Error " & Err.Number & ": " & Err.Description SendSMS = 20 Resume ExitSMSSend End Function
'Code in frmInet which contains an ms internet control inet1 Option Explicit Dim intState As Integer Dim strPageReturn
Private Sub Inet1_StateChan ged(ByVal State As Integer) On Error GoTo ErrInet1_StateC hanged ' Retrieve server response using the GetChunk ' method when State = 12. Dim vtData As Variant Dim strData As String Dim bDone As Boolean: bDone = False
intState = State Select Case State ' ... Other cases not shown. Case icError ' 11 ' In case of error, return ResponseCode and ' ResponseInfo. vtData = Inet1.ResponseC ode & ":" & _ Inet1.ResponseI nfo strPageReturn = vtData
Case icResponseCompl eted ' 12
' Get first chunk. vtData = Inet1.GetChunk( 1024, icString) DoEvents
Do While Not bDone strData = strData & vtData ' Get next chunk. vtData = Inet1.GetChunk( 1024, icString) DoEvents
If Len(vtData) = 0 Then bDone = True End If Loop
Dim a, b a = InStr(strData, "<Response> ") + 10 b = InStr(strData, "</Response>")
strPageReturn = Mid(strData, a, 2) Debug.Print strPageReturn, strData
' MsgBox strPageReturn, , "Return data" End Select
ExitInet1_State Changed: Exit Sub ErrInet1_StateC hanged: MsgBox "Error " & Err.Number & ": " & Err.Description Resume ExitInet1_State Changed End Sub
Property Get ControlState() As Byte ControlState = intState End Property
Property Get PageReturn() As String PageReturn = strPageReturn End Property This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: yaipa |
last post by:
What would be the common sense way of finding a binary pattern in a
..bin file, say some 200 bytes, and replacing it with an updated pattern
of the same length at the same offset?
Also, the pattern can occur on any byte boundary in the file, so
chunking through the code at 16 bytes a frame maybe a problem. The
file itself isn't so large,...
|
by: John |
last post by:
Hi
First of all apologies for posting so much code but this is rather involved
and I am totally stumped. Basically I have a main form (Staff Batch
SMS/E-Mail) which calls a function (SendSMS) in a module with in turn calls
a form (frmInet) which contains an ms internet control (Inet1). Problem is
that once the function Send SMS returns and...
|
by: Anony |
last post by:
Hi All,
I'm trying to chunk a long string SourceString into lines of LineLength
using this code:
Dim sReturn As String = ""
Dim iPos As Integer = 0
Do Until iPos >= SourceString.Length - LineLength
sReturn += SourceString.Substring(iPos, LineLength) + vbCrLf
iPos += LineLength
|
by: MackS |
last post by:
Hello everyone
I am faced with the following problem. For the first time I've asked
myself "might this actually be easier to code in C rather than in
python?", and I am not looking at device drivers. : )
This program is meant to process relatively long strings (10-20 MB) by
selectively modifying small chunks one at a time. Eg, it locates...
|
by: ishtar2020 |
last post by:
Hi everybody
I've been writing my very first application in Python and everything is
running smoothly, except for a strange problem that pops up every once
in a while. I'm sure is the kind
of newbie thing every seasoned programmer knows.
Sometimes a receive strange Syntax Errors from parts of code that
worked perfectly minutes ago....
| |
by: savvy |
last post by:
I'm having some background graphics layout on the page and a table
layout on top of it. Inside the table i have two DropDownList menus
whose AutoPostBack Property is set to true and I'm using two Required
Field Validators for both the drop down menus. I dont know whats the
reason but everytime I change the dropdown menu the page takes a long...
|
by: zl2k |
last post by:
hi, all
I am not sure of this question is suitable for the c++ language group
but still hope the experts here can give me some hints.
I am using gcc 3.4.4 in fc3 and got a very strang error when using
optimization O2 or O3 (the program runs fine if not using
optimization).
Very strange, I can avoid the error by writing in this way:
|
by: SpreadTooThin |
last post by:
I have a list and I need to do a custom sort on it...
for example:
a = #Although not necessarily in order
def cmp(i,j): #to be defined in this thread.
a.sort(cmp)
print a
|
by: suresh |
last post by:
Hi,
For this code snippet, I get the following output, which I am unable
to understand.
(2^31 = 2147483648)
cout<< -2147483648 << endl;
cout << numeric_limits<int>::min() <<',' <<
numeric_limits<int>::max()<< endl;
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |