让窗体总是处于最前面:在模块中放置如下代码。在Timer或窗体的deativate中调用窗体置前 即:call KeepOnTop(form1)Option Explicit#If Win16 Then Declare Sub SetWindowPos Lib "User" (ByVal hwnd As Integer, ByVal hWndInsertAfter As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) #Else Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long #End IfConst SWP_NOMOVE = 2 Const SWP_NOSIZE = 1 Const HWND_TOPMOST = -1 Const HWND_NOTOPMOST = -2 Const wFlags = SWP_NOMOVE Or SWP_NOSIZESub KeepOnTop(frmForm As Form) '窗体置前 SetWindowPos frmForm.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE End SubSub RemoveOnTop(frmForm As Form) '窗体取消置前 SetWindowPos frmForm.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, wFlags End Sub
听说条码扫描器会在扫描到的字符串后面加个回车。 估计是这个回车把你的msgbox给关掉了。
对呀, DragonCity(自己发工资) 说的对但是如何解决呢?
你是怎么做的阿,给点代码看看呢我也老做条码扫描器的程式,可是没遇到过你说的问题。 我一般这么做 Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 And Text1.Text <> "" Then '判断是否重复 If 重复的 Then MsgBox "该号码重复了!", vbOKOnly + vbExclamation End If End Sub
我出问题的代码如下: Private Sub Text1_Change() If Len(Text1) = 15 Then If cn.State = adStateClosed Then cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=e:\山东波导串号\sdch.mdb;Mode=ReadWrite|Share Deny None;Persist Security Info=False" End If If rs.State = adStateOpen Then
Set rs = Nothing End If rs.Open "新串号", cn, adCmdTable, adLockPessimistic If rs.Supports(adAddNew) Then rs.AddNew On Error GoTo e1 If Text3 = "" Then Text3 = "无" rs("型号") = Trim(Combo1) rs("地区") = Trim(Combo2) rs("箱号") = Text2 rs("串号") = Text1 rs("代理商") = Trim(Combo3) rs("日期") = DT1 rs("备注") = Text3 rs.Update Text1.Text = "" Exit Sub End If e1:MsgBox Err.DescriptionText1 = "" End If
end sub
试试看我的这段 Private Sub Text1_KeyPress(KeyAscii As Integer) Dim rs As ADODB.Recordset Dim sql As StringIf KeyAscii = 13 And Trim(Text1.Text) <> "" Then If Len(Trim(Text1)) <> 15 Then MsgBox "´íÎóµÄºÅÂ룡", vbOKOnly + vbExclamation Text1.SelStart 0 Text1.SelLength = Len(Text1.Text) Exit Sub End If If cn.State = adStateClosed Then cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=e:\ɽ¶«²¨µ¼´®ºÅ\sdch.mdb;Mode=ReadWrite|Share Deny None;Persist Security Info=False" sql = "select * from д®ºÅ where ´®ºÅ='" & Trim(Text1.Text) & "'" Set rstemp = cn.Execute(sql) If Not rstemp.EOF Then rstemp.Close MsgBox "Öظ´µÄºÅÂ룡", vbOKOnly + vbExclamation Text1.SelStart 0 Text1.SelLength = Len(Text1.Text) Exit Sub End If sql = "insert into д®ºÅ(ÐͺÅ,µØÇø,ÏäºÅ,´®ºÅ,´úÀíÉÌ,ÈÕÆÚ,±¸×¢) values('" & Trim(combo1.Text) & _ "','" & Trim(combo2.Text) & "','" & Trim(text2.Text) & "','" & Trim(Text1.Text) & "','" & _ Trim(combo3.Text) & "','" & dt1 & "','" & Trim(text3.Text) & "')" cn.Execute sql Text1.Text = "" Text1.SetFocus End If End Sub
End If If rs.State = adStateOpen Then
Set rs = Nothing End If 不应该是nothing,close就可以了,否则还有new一下
End If If rs.State = adStateOpen Then
Set rs = Nothing End If 不应该是nothing,close就可以了,否则还有new一下
有空整理一下! Private Sub Text1_KeyPress(KeyAscii As Integer) Dim rs As ADODB.Recordset Dim sql As StringIf KeyAscii = 13 And Trim(Text1.Text) <> "" Then If Len(Trim(Text1)) <> 15 Then MsgBox "错误的号码!", vbOKOnly + vbExclamation Text1.SelStart 0 Text1.SelLength = Len(Text1.Text) Exit Sub End If If cn.State = adStateClosed Then cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=e:\山东波导串号\sdch.mdb;Mode=ReadWrite|Share Deny None;Persist Security Info=False" end if sql = "select * from 新串号 where 串号='" & Trim(Text1.Text) & "'" Set rstemp = cn.Execute(sql) If Not rstemp.EOF Then rstemp.Close MsgBox "重复的号码!", vbOKOnly + vbExclamation Text1.SelStart 0 Text1.SelLength = Len(Text1.Text) Exit Sub End If sql = "insert into 新串号(型号,地区,箱号,串号,代理商,日期,备注) values('" & Trim(combo1.Text) & "','" & Trim(combo2.Text) & "','" & Trim(text2.Text) & "','" & Trim(Text1.Text) & "','" & Trim(combo3.Text) & "','" & dt1 & "','" & Trim(text3.Text) & "')" cn.Execute sql Text1.Text = "" Text1.SetFocus End If End Sub这样肯定OK了. 你用Change的话,多的那个回车当然只能到后面处理啦,这就是你问题的症结.
form1.setfocus
即:call KeepOnTop(form1)Option Explicit#If Win16 Then
Declare Sub SetWindowPos Lib "User" (ByVal hwnd As Integer, ByVal hWndInsertAfter As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer)
#Else
Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
#End IfConst SWP_NOMOVE = 2
Const SWP_NOSIZE = 1
Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Const wFlags = SWP_NOMOVE Or SWP_NOSIZESub KeepOnTop(frmForm As Form)
'窗体置前
SetWindowPos frmForm.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
End SubSub RemoveOnTop(frmForm As Form)
'窗体取消置前
SetWindowPos frmForm.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, wFlags
End Sub
估计是这个回车把你的msgbox给关掉了。
我一般这么做
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 And Text1.Text <> "" Then
'判断是否重复
If 重复的 Then MsgBox "该号码重复了!", vbOKOnly + vbExclamation
End If
End Sub
Private Sub Text1_Change()
If Len(Text1) = 15 Then
If cn.State = adStateClosed Then
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=e:\山东波导串号\sdch.mdb;Mode=ReadWrite|Share Deny None;Persist Security Info=False"
End If
If rs.State = adStateOpen Then
Set rs = Nothing
End If
rs.Open "新串号", cn, adCmdTable, adLockPessimistic
If rs.Supports(adAddNew) Then
rs.AddNew
On Error GoTo e1
If Text3 = "" Then Text3 = "无"
rs("型号") = Trim(Combo1)
rs("地区") = Trim(Combo2)
rs("箱号") = Text2
rs("串号") = Text1
rs("代理商") = Trim(Combo3)
rs("日期") = DT1
rs("备注") = Text3
rs.Update
Text1.Text = ""
Exit Sub
End If
e1:MsgBox Err.DescriptionText1 = ""
End If
end sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
Dim rs As ADODB.Recordset
Dim sql As StringIf KeyAscii = 13 And Trim(Text1.Text) <> "" Then
If Len(Trim(Text1)) <> 15 Then
MsgBox "´íÎóµÄºÅÂ룡", vbOKOnly + vbExclamation
Text1.SelStart 0
Text1.SelLength = Len(Text1.Text)
Exit Sub
End If
If cn.State = adStateClosed Then cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=e:\ɽ¶«²¨µ¼´®ºÅ\sdch.mdb;Mode=ReadWrite|Share Deny None;Persist Security Info=False"
sql = "select * from д®ºÅ where ´®ºÅ='" & Trim(Text1.Text) & "'"
Set rstemp = cn.Execute(sql)
If Not rstemp.EOF Then
rstemp.Close
MsgBox "Öظ´µÄºÅÂ룡", vbOKOnly + vbExclamation
Text1.SelStart 0
Text1.SelLength = Len(Text1.Text)
Exit Sub
End If
sql = "insert into д®ºÅ(ÐͺÅ,µØÇø,ÏäºÅ,´®ºÅ,´úÀíÉÌ,ÈÕÆÚ,±¸×¢) values('" & Trim(combo1.Text) & _
"','" & Trim(combo2.Text) & "','" & Trim(text2.Text) & "','" & Trim(Text1.Text) & "','" & _
Trim(combo3.Text) & "','" & dt1 & "','" & Trim(text3.Text) & "')"
cn.Execute sql
Text1.Text = ""
Text1.SetFocus
End If
End Sub
If rs.State = adStateOpen Then
Set rs = Nothing
End If
不应该是nothing,close就可以了,否则还有new一下
If rs.State = adStateOpen Then
Set rs = Nothing
End If
不应该是nothing,close就可以了,否则还有new一下
Private Sub Text1_KeyPress(KeyAscii As Integer)
Dim rs As ADODB.Recordset
Dim sql As StringIf KeyAscii = 13 And Trim(Text1.Text) <> "" Then
If Len(Trim(Text1)) <> 15 Then
MsgBox "错误的号码!", vbOKOnly + vbExclamation
Text1.SelStart 0
Text1.SelLength = Len(Text1.Text)
Exit Sub
End If
If cn.State = adStateClosed Then
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=e:\山东波导串号\sdch.mdb;Mode=ReadWrite|Share Deny None;Persist Security Info=False"
end if
sql = "select * from 新串号 where 串号='" & Trim(Text1.Text) & "'"
Set rstemp = cn.Execute(sql)
If Not rstemp.EOF Then
rstemp.Close
MsgBox "重复的号码!", vbOKOnly + vbExclamation
Text1.SelStart 0
Text1.SelLength = Len(Text1.Text)
Exit Sub
End If
sql = "insert into 新串号(型号,地区,箱号,串号,代理商,日期,备注) values('" & Trim(combo1.Text) & "','" & Trim(combo2.Text) & "','" & Trim(text2.Text) & "','" & Trim(Text1.Text) & "','" & Trim(combo3.Text) & "','" & dt1 & "','" & Trim(text3.Text) & "')"
cn.Execute sql
Text1.Text = ""
Text1.SetFocus
End If
End Sub这样肯定OK了.
你用Change的话,多的那个回车当然只能到后面处理啦,这就是你问题的症结.