Results 1 to 2 of 2
  1. #1
    emilysam is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jan 2016
    Posts
    1

    Thumbs down Help with using custom control in VBA

    I am trying to use a custom control that is a 3rd party implementation of the VB Winsock control. The control is called OSWinsock (http://www.ostrosoft.com/oswinsck/os...reference.aspx). I have added this as a reference into VBA and can create the oswinsock object. I am having trouble using the controls methods properly though. Based on the example provided by the author, I added the control into my form via the following:

    Option Compare Database
    Option Explicit


    Dim WithEvents wsTCP As OSWINSCK.Winsock

    This now provides the following events to the form:

    object.OnClose()
    connection closed

    object.OnConnect()
    connection to remote host established

    object.OnConnectionRequest(requestID As Long)
    connection request from remote host

    object.OnDataArrival(bytesTotal As Long)
    new data arrived



    object.OnError(Number As Integer, Description As String, Scode As Long, Source As String, HelpFile As String, HelpContext As Long, CancelDisplay As Boolean)
    error occured

    object.OnSendComplete()
    data send is complete

    object.OnSendProgress(bytesSent As Long, bytesRemaining As Long)
    data send is in progress

    object.OnStatusChanged(ByVal Status As String)
    component status changed

    On my access form, I have a command button that runs a bunch of VBA code and then calls the Connect method of the oswinsock object as follows:

    Set wsTCP = CreateObject("OSWINSCK.Winsock")

    wsTCP.Connect strServer, lngPort


    The connection is made successfully as in the OnConnect event of the wsTCP object I get the following from a debug statement that calls the wsTCP.Status property:

    wsTCP_OnConnect: wsTCP.Status = Connect

    Also, in the OnDataArrival event of the wsTCP object I have the following and I can see that the remote server responded when I read the value of strTemp

    wsTCP.GetData strTemp


    My problem is this. I need to programmatically communicate with the remote server using multiple calls to the SendData and GetData methods of the wsTCP object. I thought I could simply call the Connect method and then do something like this, all within the same OnClick event from the command button on my form. Something like this:

    Set wsTCP = CreateObject("OSWINSCK.Winsock")

    wsTCP.Connect strServer, lngPort

    wsTCP.GetData strTemp 'get response from server after connection is made

    wsTCP.SendData strDataToSend

    wsTCP.GetData strTemp 'get response after sending 1st command

    wsTCP.SendData strDataToSend 'send the next command

    etc... (including other code to check that the connection has been made, send the responses to a buffer, etc)

    However, even though I call the Connect method, the connection doesn't get made until AFTER the rest of the code in the OnClick event of the command button completes. If I take all that other code (GetData/SendData) and put it into a different Command button and click it, it executes successfully, i.e. the Connect method opens a socket to the remote server after I click Command button1 and then code from Command button 2 uses that open socket connection to SendData/GetData successfully. I need to make multiple connections to different servers that I read in from a file so I need this to all happen programmatically without the need to click on a second command button to actually communicate with the remote server.

    Any advice would be helpful.

    Thanks


  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    Maybe DoEvents function will help:

    While Timer < Start + 3
    DoEvents
    Wend

    https://support.office.com/en-us/art...F-0B3D4C2575B0
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 10-06-2015, 06:50 AM
  2. Replies: 8
    Last Post: 06-19-2015, 02:19 AM
  3. Replies: 2
    Last Post: 05-27-2014, 11:32 AM
  4. Replies: 3
    Last Post: 03-29-2012, 12:40 PM
  5. Replies: 1
    Last Post: 02-27-2012, 06:22 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums