It seems to me I once saw code that wrote to a serial port using standard file processing statements (Open, Write, and Close). You just have to use the port name (with a trailing colon) as the file path. For example,
Dim iFile As Integer
iFile = FreeFile()
Open "COM1:" For Output As iFile
Write #iFile, "ATDT nnn-nnnn" & vbCrLf
Close #iFile
I could be just imagining this, but if it works, it sure is an easier method than using the Windows commlib. (Make sure you handle errors, though--in case the port is busy.) Rick Sprague
The Windows commlib (not an actual name, just an abbreviation I'm using) is the part of the Windows API that supports accessing the serial communications ports. Like any Windows API, you need to get some documentation of how it works, and then code Declare Function statements to invoke it from VBA code. And like most APIs, its relatively "down to the metal" compared to VB, so you should think of it as a medium-hard programming task.
An excellent resource for using the Windows API is the book "Visual Basic Programmer's Guide to the Windows API" by (I think) Daniel Appleman. This is a "must have" on professional VB and VBA programmers' bookshelves.
I just noticed you said you're using VB4. This forum is for Access only. If you plan to continue seeking information, you need to do so in some other forum.
Rick Sprague
I still haven't figured out how to send data to a serial port in Access 97 (or VB 4 for that matter, if I can be forgiven for mentioning that on the Access board). Neither of the above have "MSCOMM" anywhere that I can find.
I am able to do it in QuickBasic, then shell out to send the data, but that seems like a clumsy way to make it happen.
Since I'm generating the data in an access database, I'd like to be able to send it directly from there.
I have also been trying to use a serial RS-232 port through Access 97 to read an instrument directly in a table.
I was checking answers to your post, and I have been searching the web quite a lot these last days, and it seems that VBA has no control to do that like MSCOMM in VB6, so the solutions would be (as far as I understood) :
- use APIs functions, seems difficult
- or write one's own control in VB6 to use it in VBA, I just found that somebody did it for us and it is a freeware. Have a look there :
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.