所以我现在正在努力解决如何让我的程序在vb6中运行的问题。命令按钮的功能是当TLoginR.text在数据库中具有相同的文本时,它将显示一个消息框,指出“用户名不可用...”。现在问题是,当我键入新文本但不在数据库中时,提示仍然会弹出。我非常需要帮助,谢谢。
代码:
Private Sub CRegR_Click()
Dim user as string
Dim pass as string
Dim prompt as string
RegR.Refresh
user = TLoginR.Text
pass = TPassR.Text
Do Until Regr.Recordset.EOF
If RegR.Recordset.Fields("Username").Value = user Then
prompt = MsgBox("Username not available, please try another one!", vbOKCancel)
If (prompt = 1) Then
TLoginR.Text = ""
TPassR.Text = ""
Register.show
Else
End If
Exit Sub
Else
RegR.Recordset.MoveNext
End If
Loop
RegR.Recordset.Fields("Username").value = user
RegR.Recordset.Fields("Password").value = pass
RegR.Recordset.Update
Register.Hide
Login.Show
End Sub
答案 0 :(得分:0)
我将假设您的记录集包含表中的每条记录。我还假设你在其他地方防范空用户名。我怀疑你可能有你不希望有的记录,因为你没有在开始迭代之前将记录集移动到第一个记录。但是,这是基于我正在做的假设,因为我们无法看到该代码。
Private Sub CRegR_Click()
Dim user As String
Dim pass As String
Dim prompt As String
RegR.Refresh
user = TLoginR.Text
pass = TPassR.Text
RegR.Recordset.MoveFirst 'return to the first record
Do Until RegR.Recordset.EOF
If StrComp(RegR.Recordset.Fields("Username").Value, user, vbTextCompare) = 0 Then
prompt = MsgBox("Username not available, please try another one!", vbOKCancel)
If (prompt = vbOK) Then
TLoginR.Text = ""
TPassR.Text = ""
Register.Show
Else
'do domething?
End If
Exit Sub
Else
RegR.Recordset.MoveNext
End If
Loop
RegR.Recordset.Fields("Username").Value = user
RegR.Recordset.Fields("Password").Value = pass
RegR.Recordset.Update
Register.Hide
Login.Show
End Sub