Run-Time Error '424' Objekt Erforderlich - Fehler MoveFirst

Habe ich einen login-Bildschirm mit einer dropdown-Liste, die Ihre MSID aus der Tabelle tTbl_LoginUsers
Die MSID entspricht der PKUserId (eine ganze Zahl), wie unten

PKUserID    MSID
1           jjenki02
2           trensc01 

Ich brauche den code unten Hinweis: die PKUserID verwendet werden, für LngLongID, die Orte, die 1 oder 2 entsprechenden PKUSERID der MSID in meine tTbl_LoginSessions in der Spalte fldUserName, aber die Ausführung, das gibt mir die Run-Time Error '424' Objekt Erforderlich. Ich kann nicht für das Leben von mir herauszufinden, warum? Irgendwelche Ideen?

Private Sub CboUser_Click()
Dim MyCon As ADODB.Connection
Dim MyRS As ADODB.Recordset

    Set MyCon = New ADODB.Connection
    MyCon.Open "DRIVER=SQL Server;SERVER=dbswd****;UID=*****;PWD=*****;DATABASE=Regulatory;"
    Set MyRS = New ADODB.Recordset

'/The following code focuses on the DropDown field that the User selects their MSID
'/if MyNum = MSID, then MoveFirst to get the PKUserID(Column 1)from tTbl_LoginUsers
CboUser.SetFocus
MyNum = CboUser.Text
MyRS.Open "Select * from dbo.tTbl_LoginUsers Where MSID = '" & MyNum & "'", MyCon
Debug.Print strSQL

NewRecordRS.MoveFirst

LngLoginId = NewRecordRS!fldUserName


End Sub

NEUEN CODE ANGEPASST:
tTbl_LoginSessions hat die folgenden Felder: fldloginkey, fldUserName, fldLoginEvent, fld LogoutEvent, fldComputerName.
.MoveFirst löst es

Private Sub CboUser_Click()
Dim MyCon As ADODB.Connection
Dim MyRS As ADODB.Recordset

    Set MyCon = New ADODB.Connection
    MyCon.Open "DRIVER=SQL Server;SERVER=dbswd0027;UID=Mickey01;PWD=Mouse02;DATABASE=Regulatory;"
    Set MyRS = New ADODB.Recordset

With MyRS
'/The following code focuses on the DropDown field that the User selects their MSID
'/if that MyNum = MSID, then MoveFirst to get the PKUserID(Column 1)from tTbl_LoginUsers
     CboUser.SetFocus
     MyNum = CboUser.Text
     MyRS.Open "Select * from dbo.tTbl_LoginUsers Where MSID = '" & MyNum & "'", MyCon
     Debug.Print strSQL

   If Not (.BOF And .EOF) Then
        .MoveFirst
        LngLoginId = !fldUserName
    End If
End With
Debug.Print strSQL
'NewRecordRS.MoveFirst
'LngLoginId = NewRecordRS!fldUserName


End Sub

DIES IST DER CODE, Orte, PKUSERID in die Login-Sitzungen:

Function CreateSession()
'/This function records the details regarding the login details of the person

Dim con As ADODB.Connection
Dim cmd As ADODB.Command
Dim strSQL As String
Dim WhoAmI As Long

Set NewIdentRS = New ADODB.Recordset

Dim LngLoginId As String, StrComputerName As String


'passing variables
StrMSID = LngLoginId
'old StrMSID = StrLoginName
StrComputerName = FindComputerName

   'Declaring what table you are passing the variables to
    strSQL = "Insert into dbo.tTbl_LoginSessions(fldUserName, fldLoginEvent, fldComputerName) Values ('" & StrMSID & "','" & Now() & "','" & StrComputerName & "')"
     Debug.Print strSQL

    'connect to SQL Server
    Set con = New ADODB.Connection
    With con
        .ConnectionString = cSQLConn
        .Open
    End With

    'write back
    Set cmd = New ADODB.Command
    With cmd
        .ActiveConnection = con
        .CommandText = strSQL
        .CommandType = adCmdText
        .Execute


    End With

    con.Close
    Set cmd = Nothing
    Set con = Nothing



End Function

Ich habe auch dieses:

Public Function GrabMSID(frmObject)
GrabMSID = LngUserID
End Function
'Call it this way:
MyMSID = GrabMSID(Me)


Option Compare Database
Public LngLoginId As Long
Insert into dbo.tTbl_LoginSessions(fldUserName, fldLoginEvent, fldComputerName) Werte (",'11/4/2013 9:38:26 BIN','LH7U0CNU139430Z') Der code funktioniert Super setzen von Datum/Uhrzeit und Benutzer der Maschine, aber die ersten Zitate haben sollte, die ganze Zahl, die wir versuchen, durch zu bekommen.

InformationsquelleAutor T-Rex | 2013-11-01

Schreibe einen Kommentar