Re: Using with statement to Open aTable
From: Brendan Reynolds (brenreyn)
Date: 02/17/05
- Next message: Jörg Ackermann: "Re: Using with statement to Open aTable"
- Previous message: iholder: "Re: Using with statement to Open aTable"
- In reply to: iholder: "Re: Using with statement to Open aTable"
- Next in thread: Jörg Ackermann: "Re: Using with statement to Open aTable"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 17 Feb 2005 13:38:11 -0000
You can still use the Execute method, you just have to replace the reference
to CurrentUser() with a reference to wherever your user ID is stored. And
this will be the most efficient way to do it. if you really want to use a
recordset though ...
Public Sub AddRecord()
'Using DAO
Dim db As DAO.Database
Dim rstd As DAO.Recordset
Set db = CurrentDb
Set rstd = db.OpenRecordset("SELECT TestText, TestDate FROM tblTest", ,
dbAppendOnly)
With rstd
.AddNew
.Fields("TestText") = "My User ID 1"
.Fields("TestDate") = Now()
.Update
.Close
End With
'Using ADO
Dim rsta As ADODB.Recordset
Set rsta = New ADODB.Recordset
With rsta
.ActiveConnection = CurrentProject.Connection
.LockType = adLockOptimistic
.Source = "SELECT TestText, TestDate FROM tblTest"
.Open
.AddNew
.Fields("TestText") = "My User ID 2"
.Fields("TestDate") = Now()
.Update
.Close
End With
End Sub
-- Brendan Reynolds (MVP) "iholder" <iholder@discussions.microsoft.com> wrote in message news:29413D83-E891-41F7-8753-F339912DA797@microsoft.com... > CurrentDb.Execute "insert into tblLogin (userID, Login) Values >> (CurrentUser(), Now());" > This code is not working for me. All I need is a easy way to open a table > and add a record. I am not trying to get network user info. using a > recordset and "with statement. > > > "Joerg Ackermann" wrote: > >> iholder wrote: >> >> > I am setting up login tracking. Need to open table in the add mode >> > and data to the following fields . [UserID], [LogInTime], [LogDate] >> > >> > Table is not attached any form or report. >> > Is the "with" statement the right approach, if not please suggest. >> >> I would not split Logdate and logintime in two fields. >> It's simple to get Date or time using Format-Function if needed. >> >> CurrentDb.Execute "insert into tblLogin (userID, Login) Values >> (CurrentUser(), Now());" >> >> Acki >> >>
- Next message: Jörg Ackermann: "Re: Using with statement to Open aTable"
- Previous message: iholder: "Re: Using with statement to Open aTable"
- In reply to: iholder: "Re: Using with statement to Open aTable"
- Next in thread: Jörg Ackermann: "Re: Using with statement to Open aTable"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|