|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
前辈们:帮忙看看我的一个单元格出发事件一直提示“无此会员!请先录入此会员!”,不知道是哪里出了问题,原本想是没有记录时提示“无此会员!请先录入此会员!”,如果有则显示此会员,我将代码和附件全上传,请前辈们帮帮忙!谢谢!
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub '
If Target.Column <> 7 Then Exit Sub
If Target.Row = Range("ins").Row - 1 Then
Range(Cells(19, 20), Cells(Range("ins").Row - 1, 20)).Formula = "=HzToPy($F19,,FALSE,TRUE)&IF(LEN(MONTH($G19))=1,0&MONTH($G19),MONTH($G19))&IF(LEN(DAY($G19))=1,0&DAY($G19),DAY($G19))"
Range(Cells(19, 21), Cells(Range("ins").Row - 1, 21)).Formula = "=SUBSTITUTE($T19," & """ """ & "," & """""" & ")"
Range(Cells(19, 9), Cells(Range("ins").Row - 1, 9)) = "=QUOTIENT(D19-G19,365)&""岁"""IENT(MOD(D19-G19,365),30)&""个月"""
Sheets("sheet2").Cells(Range("ins").Row - 1, 3) = Sheets("sheet2").Cells(Range("ins").Row - 1, 21).Value
End If
If Target <> "" Then
Dim conn As Object
Dim rst As Object
Dim Sql1$, Sql$
Sql1 = "select * from 会员记录 where 会员名 = '" & Cells(Range("ins").Row - 1, 3) & "'"
Set conn = CreateObject("adodb.connection")
Set rst = CreateObject("adodb.Recordset")
With conn
.Provider = "microsoft.ACE.oledb.12.0"
.ConnectionString = "Data Source =" & ThisWorkbook.Path & "\shuju.accdb"
.Open
End With
rst.Open Sql1, conn, 1, 3
'我想做到如果“会员记录”没有记录则出现一次提示,然后执行其他代码,结果现在出现无数次的提示!
If rst.EOF Then
MsgBox ("无此会员!请先录入此会员!") '如果把这句删除,则会弹出下面的错图提示,光标定位在 rst.Open Sql1, conn, 1, 3处
Sheets("sheet2").Range("C6") = Sheets("sheet2").Cells(Range("ins").Row - 1, 3).Value
Sheets("sheet2").Range("D6") = Sheets("sheet2").Cells(Range("ins").Row - 1, 6).Value
Sheets("sheet2").Range("G6") = Sheets("sheet2").Cells(Range("ins").Row - 1, 7).Value
Range("C12:J12").ClearContents
Range("F6").Select
Else
Range("C6:J6").ClearContents
Sql = "select 会员名,妈妈姓名,宝宝姓名,性别,出生时间,手机,手机电话,家庭住址 from 会员记录 where 会员名 = '" & Cells(Range("ins").Row - 1, 3) & "'"
Set conn = CreateObject("adodb.connection")
With conn
.Provider = "microsoft.ACE.oledb.12.0"
.ConnectionString = "Data Source =" & ThisWorkbook.Path & "\shuju.accdb"
.Open
End With
Sheets("sheet2").[C11].CurrentRegion.Offset(1).ClearContents
Sheets("sheet2").[C12].CopyFromRecordset conn.Execute(Sql)
Sheets("sheet2").Range("T12") = Sheets("sheet2").Range("C12").Value
End If
rst.Close
conn.Close
Set conn = Nothing
End If
End Sub
|
|