VB 无法在DataGrid中添加新纪录 显示名称已存在 错哪了
VB 无法在DataGrid中添加新纪录 显示名称已存在 哪里错了
请教:
一个 仓库管理模块 在添加新纪录时 显示 名称已存在,请重新输入 。
代码什么地方错了呢?
请 前辈们指点指点

这是Form3的代码
这是Form4的代码
------解决思路----------------------
学着自己排查代码
根据你的提示信息,找到对应的代码位置,然后从前面一行一行检查判断条件
请教:
一个 仓库管理模块 在添加新纪录时 显示 名称已存在,请重新输入 。
代码什么地方错了呢?
请 前辈们指点指点
这是Form3的代码
Private Sub Command1_Click()
'检查用户录入数据的有效性
If Trim(Text1) = "" Then
MsgBox "请输入仓库名称"
Text1.SetFocus
Exit Sub
End If
'把用户录入的数据赋值到MyStore对象中
With MyStore
.StoreName = MakeStr(Text1)
.Describe = MakeStr(Text2)
'判断仓库名是否存在
If Modify = False Or OriName <> Trim(Text1) Then
If .In_DB(MakeStr(Text1)) = Ture Then
MsgBox "仓库名已经存在,请重新输入"
Text1.SetFocus
Text1.SelStart = 0
Text1.SelLength = Len(Text1)
Exit Sub
End If
End If
'根据变量Modify的值,决定是插入新数据,还是修改已有的数据
If Modify = False Then
.Insert
MsgBox "添加成功"
Else
.Update (OriId)
MsgBox "修改成功"
End If
End With
Unload Me
End Sub
这是Form4的代码
Private Sub Refresh_Store()
'设置数据源,显示仓库数据
Adodc1.RecordSource = "select StoreId as 仓库编号,StoreName as 仓库名称,Describe as 描述信息 from StoreHouse order by StoreId"
'刷新数据,把新的内容反映到界面上
Adodc1.Refresh
End Sub
Private Sub Command1_Click()
Form3.Modify = False
Form3.OriId = 0
Form3.Show 1
Refresh_Store
End Sub
Private Sub Command2_Click()
'判断是否选择了仓库记录
If Adodc1.Recordset.EOF = True Then
MsgBox "请选择记录"
Exit Sub
End If
p = Adodc1.Recordset.AbsolutePosition
'把当前仓库的数据读取到FrmStoreEdit窗体的相关位置
Form3.OriId = Adodc1.Recordset.Fields(0)
Form3.OriName = Trim(Adodc1.Recordset.Fields(1))
Form3.Text1 = Trim(Adodc1.Recordset.Fields(1))
Form3.Text2 = Trim(Adodc1.Recordset.Fields(2))
'设置修改状态为真
Form3.Modify = True
Form3.Show 1
Refresh_Store
Adodc1.Recordset.Move p
End Sub
Private Sub Command3_Click()
Dim TmpId As Long
If Adodc1.Recordset.BOF = True Then
MsgBox "请选择记录"
Exit Sub
End If
p = Adodc1.Recordset.AbsolutePosition
TmpId = Adodc1.Recordset.Fields(0)
'判断入库单中是否包含此仓库
If MyStorein.HaveStore(TmpId) = True Then
MsgBox "入库单中包含此仓库,不能删除"
Exit Sub
End If
'判断出库单中是否包含此仓库
If MyTakeout.HaveStore(TmpId) = True Then
MsgBox "出库单中包含此仓库,不能删除"
Exit Sub
End If
'判断此仓库是否存放有产品
If MyEquInStore.HaveStore(TmpId) = True Then
MsgBox "此仓库中存放有产品,不能删除"
Exit Sub
End If
If MsgBox("是否删除当前行?", vbYesNo, "确认") = vbYes Then
MyStore.Delete (TmpId)
MsgBox "删除成功"
Refresh_Store
If p - 1 > 0 Then
Adodc1.Recordset.Move p - 1
End If
End If
End Sub
Private Sub Command4_Click()
Unload Me
End Sub
Private Sub Form_Load()
Refresh_Store
End Sub
------解决思路----------------------
学着自己排查代码
根据你的提示信息,找到对应的代码位置,然后从前面一行一行检查判断条件