A
Amy Blankenship
Following this example: http://www.mvps.org/access/queries/qry0003.htm
I've written the following code:
Dim pwd As String, tmpUname As String, db As database, rst As Recordset,
qry As QueryDef
Dim SSN As String, OldUName As String, Uname As String, UNum As Integer,
i As Integer, iFound As Integer
'set user name
Debug.Print CStr(Me.UserName)
If IsNull(Me.UserName) Then
tmpUname = Left(Me.FirstName & Me.LastName, 18)
Set db = CurrentDb()
Set qry = db.QueryDefs("CheckExistingUserName")
qry![Enter a UserName] = tmpUname
Set rst = qry.OpenRecordSet()
If Not rst.EOF Then
OldUName = rst(1)
For i = 0 To 9
If InStr(1, OldUName, i) < iFound Or IsEmpty(iFound) Then
iFound = InStr(1, OldUName, i)
Next
End If
If iFound > 0 Then
UNum = CInt(Right(OldUName, Len(OldUName) - iFound)) + 1
End If
Uname = tmpUname + String(2 - Len(UNum), "0") + UNum
Me.UserName.Value = Uname
End If
It errors at Set rst = qry.OpenRecordSet() Runtime error 13 type mismatch.
I'm pulling my hair out.
Any ideas?
TIA;
Amy
I've written the following code:
Dim pwd As String, tmpUname As String, db As database, rst As Recordset,
qry As QueryDef
Dim SSN As String, OldUName As String, Uname As String, UNum As Integer,
i As Integer, iFound As Integer
'set user name
Debug.Print CStr(Me.UserName)
If IsNull(Me.UserName) Then
tmpUname = Left(Me.FirstName & Me.LastName, 18)
Set db = CurrentDb()
Set qry = db.QueryDefs("CheckExistingUserName")
qry![Enter a UserName] = tmpUname
Set rst = qry.OpenRecordSet()
If Not rst.EOF Then
OldUName = rst(1)
For i = 0 To 9
If InStr(1, OldUName, i) < iFound Or IsEmpty(iFound) Then
iFound = InStr(1, OldUName, i)
Next
End If
If iFound > 0 Then
UNum = CInt(Right(OldUName, Len(OldUName) - iFound)) + 1
End If
Uname = tmpUname + String(2 - Len(UNum), "0") + UNum
Me.UserName.Value = Uname
End If
It errors at Set rst = qry.OpenRecordSet() Runtime error 13 type mismatch.
I'm pulling my hair out.
Any ideas?
TIA;
Amy