Kuka tietää hyvää VBA-opasta?
Koodia kasaillu, mut vielä on viilaamista. Ymmärtääkö tuota kukaan? :) Miten teen tuon järkevästi et aukaisen portin, avaan tietokannan ja tallenan dataa eli puskurista dataa tuonne -> rs![BarCode]ja lopuksi suljen portin.
Option Compare Database Option Explicit Private Sub MSComm1_OnComm() MSComm1.CommPort = 1 MSComm1.Handshaking = 0 MSComm1.Rthreshold = 0 MSComm1.Settings = "9600,N,8,1" MSComm1.InputLen = 0 MSComm1.PortOpen = True End Sub ' Command Button to open or close the port Private Sub Command1_Click() If MSComm1.PortOpen = False Then ' If com port is not open MSComm1.PortOpen = True ' Open it Command1.Caption = "Close Port" ' Modify the caption of the button Else MSComm1.PortOpen = False ' If the port is open the close it Command1.Caption = "Open Port" ' Again modify the caption End If End Sub Private Sub MSComm1_OnComm() MSComm1.PortOpen = False ' Close the com port End Sub Sub AddScanRecords() Dim cn As ADODB.Connection Dim rs As ADODB.Recordset Dim StartTime As Date StartTime = Now() Set cn = CurrentProject.Connection Set rs = New ADODB.Recordset rs.Open "ScanResults", cn, adOpenKeyset, adLockOptimistic ' ScanResults is the name of the table Do While Now() < StartTime + TimeSerial(0, 0, 1) ' test run for one second - can Add hours Or minutes rs.AddNew ' this is where you would wait for and insert the bar code. rs![BarCode] = "TestThisSub" ' BarCode is the field name you would replace "testthissub" with the bar code input rs![ScanDate] = Now() rs.Update Loop End Sub
Aihe on jo aika vanha, joten et voi enää vastata siihen.