-1

I have some computers with modems and others without using the same database. They db needs to determine if there is a modem installed. I found code created by KHaled El-Menshawy on the Internet which has the potential to do exactly what I want it to do but I get an "Object required" error. I think this is a simple fix, but I don't know how this object should be declared. Can anyone figure out the missing code? Here is his code:

Public Function CheckModem()
On Error GoTo Errr
If ProgBar.Value = 100 Then
   ProgBar.Value = 0
End If
Port = 1
PortinG:
MSComm1.CommPort = Port
MSComm1.PortOpen = True
ProgBar.Value = ProgBar.Value + 20
Label1.Caption = ProgBar.Value & "%"
Form1.MSComm1.Settings = "9600,N,8,1"
      MSComm1.Output = "AT" + Chr$(13)
      X = 1

      Do: DoEvents
          X = X + 1
          If X = 1000 Then MSComm1.Output = "AT" + Chr$(13)
          If X = 2000 Then MSComm1.Output = "AT" + Chr$(13)
          If X = 3000 Then MSComm1.Output = "AT" + Chr$(13)
          If X = 4000 Then MSComm1.Output = "AT" + Chr$(13)
          If X = 5000 Then MSComm1.Output = "AT" + Chr$(13)
          If X = 6000 Then MSComm1.Output = "AT" + Chr$(13)

          If X = 7000 Then
             MSComm1.PortOpen = False
             Port = Port + 1
             GoTo PortinG:

             If MSComm1.CommPort >= 6 Then
Errr:
 MsgBox "Can't Find Modem"
 GoTo done
 End If
 End If

 Loop Until MSComm1.InBufferCount >= 2

 instring = MSComm1.Input
 MSComm1.PortOpen = False
 ProgBar.Value = 100
 Label1.Caption = ProgBar.Value & "%"
 Text1.Text = "com" & Port 'MSComm1.CommPort & instring
 MsgBox "Modem found On Com" & Port

done:
End Function
Erik A
  • 31,639
  • 12
  • 42
  • 67
Rod
  • 151
  • 2
  • 4
  • 14
  • where does `MSComm1` come from? – serakfalcon Jul 18 '14 at 01:37
  • I do not know where MSComm1 comes from. This code is outside of my VBA experience. I was hoping to plug it in when it is working and then figure out how it works. I understand ports and "AT" codes but no clue how to answer your question. It looks to me like a few declarations are missing. Any idea how to make this work? – Rod Jul 18 '14 at 02:48

1 Answers1

0

MsComm1, if you are just copy and pasting from the code looks like it is a MsComm control object. You will have to add it as an additional control to the form, and then you can access its properties.

I suggest avoiding copy and pasting code that you don't understand, try to understand what it is doing and why. Alternatively, this link (from this question) gives a completely different way to do it, avoiding the need to add the control to the form.

Community
  • 1
  • 1
serakfalcon
  • 3,501
  • 1
  • 22
  • 33