这段代码里的num = rs(0)说出错了,调试的结果说BOF或EOF中的一个是“真”,或者当前的记录已删除,所需要的操作要当前的记录。小弟我不知道如何修改

这段代码里的num = rs(0)说出错了,调试的结果说BOF或EOF中的一个是“真”,或者当前的记录已删除,所需要的操作要求一个当前的记录。我不知道怎么修改,
Private Sub Form_Load()
  Dim rs As New ADODB.Recordset
  Dim SQL As String
  Dim num As Integer
  Dim temp As String
  With Gender '添加性别选项
  .AddItem "男"
  .AddItem "女"
  End With
  If flag = 1 Then '判断为添加信息
  Me.Caption = "添加" + Me.Caption
  Gender.ListIndex = 0
  SQL = "select * from PersonNum"
  Set rs = TransactSQL(SQL)
  num = rs(0)
  num = num + 1
  temp = Right(Format(10000000 + num), 7)
  Me.ID = "P" & temp
  rs.Close
  ElseIf flag = 2 Then '判断为修改信息
  Set rs = TransactSQL(gSQL)
  If rs.EOF = False Then
  With rs
  Me.ID = rs(0)
  Me.StuffName = rs(1)
  Me.Gender = rs(2)
  Me.Place = rs(3)
  Me.Age = rs(4)
  Me.Birthday = rs(5)
  Me.Degree = rs(6)
  Me.Speciality = rs(7)
  Me.Address = rs(8)
  Me.Code = rs(9)
  Me.Tel = rs(10)
  Me.Email = rs(11)
  Me.WorkTime = rs(12)
  Me.InTime = rs(13)
  Me.Dept = rs(14)
  Me.PayTime = rs(15)
  Me.Position = rs(16)
  Me.Remark = rs(17)
  End With
  rs.Close
  Me.Caption = "修改" & Me.Caption
  Me.ID.Enabled = False
  Me.StuffName.Enabled = False
  Else
  MsgBox "目前没有员工!", vbOKOnly + vbExclamation, "警告!"
  End If
  End If
End Sub

这段代码里的num = rs(0)说出错了,调试的结果说BOF或EOF中的一个是“真”,或者当前的记录已删除,所需要的操作要求一个当前的记录。我不知道怎么修改,

------解决方案--------------------
数据库里无记录?

用以下方式处理
1.
.
.
Set rs = TransactSQL(SQL)
If rs.BOF And rs.EOF Then
exit sub
endif
num = rs(0) 
.
.
2.
.
.
Set rs = TransactSQL(SQL)
If rs.RecordCount<=0 Then
exit sub
endif
num = rs(0) 
.
.

------解决方案--------------------
pls refer the above's advice
------解决方案--------------------
Set rs = TransactSQL(gSQL) 
If rs.recordcount>0 Then 
With rs 
Me.ID = rs(0) 

------解决方案--------------------
应该用 rs.BOF And rs.EOF,
rs.RecordCount 受到游标类型的影响。
------解决方案--------------------
探讨
应该用 rs.BOF And rs.EOF,
rs.RecordCount 受到游标类型的影响。

------解决方案--------------------
Set rs = TransactSQL(SQL) <== 有结果集吗?

------解决方案--------------------
Me.Caption = "添加" + Me.Caption 
Gender.ListIndex = 0 
SQL = "select * from PersonNum" 
Set rs = TransactSQL(SQL)
If rs.EOF Then
num = 1
Else
num = rs(0) + 1
End If