'以下是我的代码,我想增加一个或几个Text1控件实现输入多条信息的目的,可是不行,不知道怎么写代码,请教各位!如要增加一个Text1(5),怎么写使程序可用!
Public photoFilename As String
Dim mst As New ADODB.StreamPrivate Sub Command1_Click() '添加图片
Dim str '定义变量
CommonDialog1.Filter = "JPG图片(*.JPG)|*.JPG"
CommonDialog1.ShowOpen
If CommonDialog1.FileName <> "" Then
Image1.Picture = LoadPicture(CommonDialog1.FileName)
Picture1.Picture = LoadPicture(CommonDialog1.FileName)
photoFilename = CommonDialog1.FileName
CommonDialog1.FileName = ""
Else
CommonDialog1.FileName = ""
End If
End SubPrivate Sub Command2_Click() '添加
Command1.Enabled = True
Command2.Enabled = False
Command3.Enabled = True
For i = 0 To Text1.UBound
Text1(i).Enabled = True
Text1(i).Text = ""
Next i
Image1.Picture = LoadPicture("")
Picture1.Picture = LoadPicture("")
Text1(0).SetFocus
End SubPrivate Sub Command3_Click() '保存
'设置控件状态
Command1.Enabled = False
Command2.Enabled = True
Command3.Enabled = False
For i = 0 To Text1.UBound
If Text1(i).Text = "" Then
MsgBox "输入的信息不许为空!", , "信息提示"
Text1(0).SetFocus
Exit Sub
End If
Next i
If Image1.Picture = LoadPicture("") Then
MsgBox "系统不许照片为空!", , "信息提示"
Command1.SetFocus
Exit Sub
End If
Adodc1.Recordset.AddNew
For i = 0 To Text1.UBound
Adodc1.Recordset.Fields(i) = Text1(i).Text
Next i
mst.Type = adTypeBinary
mst.Open
If photoFilename <> "" Then mst.LoadFromFile photoFilename
Adodc1.Recordset.Fields("照片") = mst.Read
Adodc1.Recordset.Update
Adodc1.Refresh
mst.Close
End SubPrivate Sub Command4_Click()
Unload Me
End SubPrivate Sub Form_Load()
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db_test.mdb;Persist Security Info=False"
Adodc1.RecordSource = "select * from 人员表"
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
Adodc1.Recordset.MoveFirst
For i = 0 To Adodc1.Recordset.RecordCount - 1
Set Itemx = ListView1.ListItems.Add(, , Adodc1.Recordset.Fields("姓名"))
Adodc1.Recordset.MoveNext
Next i
End If
'设置控件状态
Command1.Enabled = False
Command3.Enabled = False
Command2.Enabled = True
For i = 0 To Text1.UBound
Text1(i).Enabled = False
Next i
End Sub
Private Sub ListView1_ItemClick(ByVal Item As MSComctlLib.ListItem) '显示人员信息
Adodc1.RecordSource = "select * from 人员表 where 姓名='" + ListView1.SelectedItem.Text + "'"
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
For i = 0 To Text1.UBound
Text1(i).Text = Adodc1.Recordset.Fields(i)
Next i
Set Picture1.DataSource = Adodc1
Picture1.DataField = "照片"
If Adodc1.Recordset.Fields("照片") Is Nothing Then
Picture1.Picture = LoadPicture()
End If
End If
End SubPrivate Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
If KeyAscii = 13 Then
If Index = 4 Then
Command1.SetFocus
Exit Sub
End If
Text1(Index + 1).SetFocus
End If
End Sub
Public photoFilename As String
Dim mst As New ADODB.StreamPrivate Sub Command1_Click() '添加图片
Dim str '定义变量
CommonDialog1.Filter = "JPG图片(*.JPG)|*.JPG"
CommonDialog1.ShowOpen
If CommonDialog1.FileName <> "" Then
Image1.Picture = LoadPicture(CommonDialog1.FileName)
Picture1.Picture = LoadPicture(CommonDialog1.FileName)
photoFilename = CommonDialog1.FileName
CommonDialog1.FileName = ""
Else
CommonDialog1.FileName = ""
End If
End SubPrivate Sub Command2_Click() '添加
Command1.Enabled = True
Command2.Enabled = False
Command3.Enabled = True
For i = 0 To Text1.UBound
Text1(i).Enabled = True
Text1(i).Text = ""
Next i
Image1.Picture = LoadPicture("")
Picture1.Picture = LoadPicture("")
Text1(0).SetFocus
End SubPrivate Sub Command3_Click() '保存
'设置控件状态
Command1.Enabled = False
Command2.Enabled = True
Command3.Enabled = False
For i = 0 To Text1.UBound
If Text1(i).Text = "" Then
MsgBox "输入的信息不许为空!", , "信息提示"
Text1(0).SetFocus
Exit Sub
End If
Next i
If Image1.Picture = LoadPicture("") Then
MsgBox "系统不许照片为空!", , "信息提示"
Command1.SetFocus
Exit Sub
End If
Adodc1.Recordset.AddNew
For i = 0 To Text1.UBound
Adodc1.Recordset.Fields(i) = Text1(i).Text
Next i
mst.Type = adTypeBinary
mst.Open
If photoFilename <> "" Then mst.LoadFromFile photoFilename
Adodc1.Recordset.Fields("照片") = mst.Read
Adodc1.Recordset.Update
Adodc1.Refresh
mst.Close
End SubPrivate Sub Command4_Click()
Unload Me
End SubPrivate Sub Form_Load()
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db_test.mdb;Persist Security Info=False"
Adodc1.RecordSource = "select * from 人员表"
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
Adodc1.Recordset.MoveFirst
For i = 0 To Adodc1.Recordset.RecordCount - 1
Set Itemx = ListView1.ListItems.Add(, , Adodc1.Recordset.Fields("姓名"))
Adodc1.Recordset.MoveNext
Next i
End If
'设置控件状态
Command1.Enabled = False
Command3.Enabled = False
Command2.Enabled = True
For i = 0 To Text1.UBound
Text1(i).Enabled = False
Next i
End Sub
Private Sub ListView1_ItemClick(ByVal Item As MSComctlLib.ListItem) '显示人员信息
Adodc1.RecordSource = "select * from 人员表 where 姓名='" + ListView1.SelectedItem.Text + "'"
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
For i = 0 To Text1.UBound
Text1(i).Text = Adodc1.Recordset.Fields(i)
Next i
Set Picture1.DataSource = Adodc1
Picture1.DataField = "照片"
If Adodc1.Recordset.Fields("照片") Is Nothing Then
Picture1.Picture = LoadPicture()
End If
End If
End SubPrivate Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
If KeyAscii = 13 Then
If Index = 4 Then
Command1.SetFocus
Exit Sub
End If
Text1(Index + 1).SetFocus
End If
End Sub
'设置控件状态
Command1.Enabled = False
Command2.Enabled = True
Command3.Enabled = False
For i = 0 To Text1.UBound
If Text1(i).Text = "" Then
MsgBox "输入的信息不许为空!", , "信息提示"
Text1(0).SetFocus
Exit Sub
End If
Next i
If Image1.Picture = LoadPicture("") Then
MsgBox "系统不许照片为空!", , "信息提示"
Command1.SetFocus
Exit Sub
End If
Adodc1.Recordset.AddNew
For i = 0 To Text1.UBound
Adodc1.Recordset.Fields(i) = Text1(i).TextNext i
mst.Type = adTypeBinary
mst.Open
If photoFilename <> "" Then mst.LoadFromFile photoFilename
Adodc1.Recordset.Fields("照片") = mst.Read
Adodc1.Recordset.Update
Adodc1.Refresh
mst.Close
End Sub
出错,