PC Review


Reply
Thread Tools Rate Thread

Date string and Charater string syntax

 
 
=?Utf-8?B?aWhvbGRlcg==?=
Guest
Posts: n/a
 
      18th Feb 2005
I need some help on setup up a syntax string for finding UserID and Log date
and blank Time field.

Here is my code

Dim rs As DAO.Recordset
Dim strLogDate As Date
Dim strFind As String
strLogDate = Date
strUserId = Me.UserID
strFind = "UserId = '" & strUserId & "'" {need the correct date and null
string added here}

'open login table
Set db = CurrentDb
Set rs = db.OpenRecordset("tblLogIntracking", dbOpenDynaset)
With rs
.MoveLast
'find login record
.FindFirst strFind
If .NoMatch Then
MsgBox "No records found"
Exit Function
Else
MsgBox "Records found"
End If
'add log time
.Edit
!LogOutTime = Time
.Update
End With

rs.Close: Set rs = Nothing
Set db = Nothing


thank you
ih


 
Reply With Quote
 
 
 
 
Dirk Goldgar
Guest
Posts: n/a
 
      18th Feb 2005
"iholder" <(E-Mail Removed)> wrote in message
news:51AD39B5-B339-42B1-AEF6-(E-Mail Removed)
> I need some help on setup up a syntax string for finding UserID and
> Log date and blank Time field.
>
> Here is my code
>
> Dim rs As DAO.Recordset
> Dim strLogDate As Date
> Dim strFind As String
> strLogDate = Date
> strUserId = Me.UserID
> strFind = "UserId = '" & strUserId & "'" {need the correct date
> and null string added here}
>
> 'open login table
> Set db = CurrentDb
> Set rs = db.OpenRecordset("tblLogIntracking", dbOpenDynaset)
> With rs
> .MoveLast
> 'find login record
> .FindFirst strFind
> If .NoMatch Then
> MsgBox "No records found"
> Exit Function
> Else
> MsgBox "Records found"
> End If
> 'add log time
> .Edit
> !LogOutTime = Time
> .Update
> End With
>
> rs.Close: Set rs = Nothing
> Set db = Nothing
>
>
> thank you
> ih


I'm not sure what you're asking with regard to the time field, and you
don't say what field in the table holds the date. Do you have a
LogInDate and a LogOutDate? A LogInTime and a LogOutTime? I'm going to
guess that you have just one date, LogDate, and two times, LogInTime and
LogOutTime, and that you want to update the record that has the current
date as the LogDate and has Null as the LogOutTime. In that case, your
code could be corrected as follows:

'----- start of revised code #1 -----
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strLogDate As String '*** NOTE CHANGE ***
Dim strFind As String

strLogDate = Format(Date, "\#mm/dd/yyyy\#")
strUserId = Me.UserID
strFind = _
"UserId = '" & strUserId & "'" & _
" AND LogDate = " & strLogDate & _
" AND LogOutTime Is Null"

'open login table
Set db = CurrentDb
Set rs = db.OpenRecordset("tblLogIntracking", dbOpenDynaset)
With rs

'find login record
.FindFirst strFind

If .NoMatch Then
MsgBox "No records found"
Else
MsgBox "Records found"
'add log time
.Edit
!LogOutTime = Time
.Update
End If

.Close

End With

Set rs = Nothing
Set db = Nothing

'----- end of revised code #1 -----

However, this would be more efficient:

'----- start of revised code #2 -----
Dim db As DAO.Database
Dim strLogDate As String
Dim strSQL As String

strLogDate = Format(Date, "\#mm/dd/yyyy\#")
strUserId = Me.UserID

strSQL = _
"UPDATE tblLogInTracking SET LogOutTime = Time() " & _
"WHERE UserId = '" & strUserId & "'" & _
" AND LogDate = " & strLogDate & _
" AND LogOutTime Is Null"

Set db = CurrentDb

With db
.Execute strSQL, dbFailOnError
If .RecordsAffected = 0 Then
MsgBox "No records found"
Else
MsgBox "Records found and updated"
End If
End With

Set db = Nothing
'----- end of revised code #2 -----

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


 
Reply With Quote
 
=?Utf-8?B?aWhvbGRlcg==?=
Guest
Posts: n/a
 
      18th Feb 2005
Thank you, Dirk

This is exactly what I wanted to do.

I went with you second code. But I am getting an error "Too few parameters.
Expected 1." Maybe a problem with the SQL syntax

"Dirk Goldgar" wrote:

> "iholder" <(E-Mail Removed)> wrote in message
> news:51AD39B5-B339-42B1-AEF6-(E-Mail Removed)
> > I need some help on setup up a syntax string for finding UserID and
> > Log date and blank Time field.
> >
> > Here is my code
> >
> > Dim rs As DAO.Recordset
> > Dim strLogDate As Date
> > Dim strFind As String
> > strLogDate = Date
> > strUserId = Me.UserID
> > strFind = "UserId = '" & strUserId & "'" {need the correct date
> > and null string added here}
> >
> > 'open login table
> > Set db = CurrentDb
> > Set rs = db.OpenRecordset("tblLogIntracking", dbOpenDynaset)
> > With rs
> > .MoveLast
> > 'find login record
> > .FindFirst strFind
> > If .NoMatch Then
> > MsgBox "No records found"
> > Exit Function
> > Else
> > MsgBox "Records found"
> > End If
> > 'add log time
> > .Edit
> > !LogOutTime = Time
> > .Update
> > End With
> >
> > rs.Close: Set rs = Nothing
> > Set db = Nothing
> >
> >
> > thank you
> > ih

>
> I'm not sure what you're asking with regard to the time field, and you
> don't say what field in the table holds the date. Do you have a
> LogInDate and a LogOutDate? A LogInTime and a LogOutTime? I'm going to
> guess that you have just one date, LogDate, and two times, LogInTime and
> LogOutTime, and that you want to update the record that has the current
> date as the LogDate and has Null as the LogOutTime. In that case, your
> code could be corrected as follows:
>
> '----- start of revised code #1 -----
> Dim db As DAO.Database
> Dim rs As DAO.Recordset
> Dim strLogDate As String '*** NOTE CHANGE ***
> Dim strFind As String
>
> strLogDate = Format(Date, "\#mm/dd/yyyy\#")
> strUserId = Me.UserID
> strFind = _
> "UserId = '" & strUserId & "'" & _
> " AND LogDate = " & strLogDate & _
> " AND LogOutTime Is Null"
>
> 'open login table
> Set db = CurrentDb
> Set rs = db.OpenRecordset("tblLogIntracking", dbOpenDynaset)
> With rs
>
> 'find login record
> .FindFirst strFind
>
> If .NoMatch Then
> MsgBox "No records found"
> Else
> MsgBox "Records found"
> 'add log time
> .Edit
> !LogOutTime = Time
> .Update
> End If
>
> .Close
>
> End With
>
> Set rs = Nothing
> Set db = Nothing
>
> '----- end of revised code #1 -----
>
> However, this would be more efficient:
>
> '----- start of revised code #2 -----
> Dim db As DAO.Database
> Dim strLogDate As String
> Dim strSQL As String
>
> strLogDate = Format(Date, "\#mm/dd/yyyy\#")
> strUserId = Me.UserID
>
> strSQL = _
> "UPDATE tblLogInTracking SET LogOutTime = Time() " & _
> "WHERE UserId = '" & strUserId & "'" & _
> " AND LogDate = " & strLogDate & _
> " AND LogOutTime Is Null"
>
> Set db = CurrentDb
>
> With db
> .Execute strSQL, dbFailOnError
> If .RecordsAffected = 0 Then
> MsgBox "No records found"
> Else
> MsgBox "Records found and updated"
> End If
> End With
>
> Set db = Nothing
> '----- end of revised code #2 -----
>
> --
> Dirk Goldgar, MS Access MVP
> www.datagnostics.com
>
> (please reply to the newsgroup)
>
>
>

 
Reply With Quote
 
Dirk Goldgar
Guest
Posts: n/a
 
      18th Feb 2005
"iholder" <(E-Mail Removed)> wrote in message
news:AEAA4502-49F2-47CC-A097-(E-Mail Removed)
> Thank you, Dirk
>
> This is exactly what I wanted to do.
>
> I went with you second code. But I am getting an error "Too few
> parameters. Expected 1." Maybe a problem with the SQL syntax
>
> "Dirk Goldgar" wrote:
>

[...]
>> However, this would be more efficient:
>>
>> '----- start of revised code #2 -----
>> Dim db As DAO.Database
>> Dim strLogDate As String
>> Dim strSQL As String
>>
>> strLogDate = Format(Date, "\#mm/dd/yyyy\#")
>> strUserId = Me.UserID
>>
>> strSQL = _
>> "UPDATE tblLogInTracking SET LogOutTime = Time() " & _
>> "WHERE UserId = '" & strUserId & "'" & _
>> " AND LogDate = " & strLogDate & _
>> " AND LogOutTime Is Null"
>>
>> Set db = CurrentDb
>>
>> With db
>> .Execute strSQL, dbFailOnError
>> If .RecordsAffected = 0 Then
>> MsgBox "No records found"
>> Else
>> MsgBox "Records found and updated"
>> End If
>> End With
>>
>> Set db = Nothing
>> '----- end of revised code #2 -----


You'll get that message if the database engine doesn't recognize one of
the names used in the SQL statement. I only guessed at "LogDate" as the
name of the date field; is it "LogInDate", maybe, or some other name
than I guessed? If so, you need to change the name used in building the
SQL statement.

Another possibility would be that you aren't running the query from
Microsoft Access. If you run it from some other application, I don't
think the Time() function will be recognized.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


 
Reply With Quote
 
=?Utf-8?B?aWhvbGRlcg==?=
Guest
Posts: n/a
 
      18th Feb 2005
Thank You, All is running fine.


"Dirk Goldgar" wrote:

> "iholder" <(E-Mail Removed)> wrote in message
> news:AEAA4502-49F2-47CC-A097-(E-Mail Removed)
> > Thank you, Dirk
> >
> > This is exactly what I wanted to do.
> >
> > I went with you second code. But I am getting an error "Too few
> > parameters. Expected 1." Maybe a problem with the SQL syntax
> >
> > "Dirk Goldgar" wrote:
> >

> [...]
> >> However, this would be more efficient:
> >>
> >> '----- start of revised code #2 -----
> >> Dim db As DAO.Database
> >> Dim strLogDate As String
> >> Dim strSQL As String
> >>
> >> strLogDate = Format(Date, "\#mm/dd/yyyy\#")
> >> strUserId = Me.UserID
> >>
> >> strSQL = _
> >> "UPDATE tblLogInTracking SET LogOutTime = Time() " & _
> >> "WHERE UserId = '" & strUserId & "'" & _
> >> " AND LogDate = " & strLogDate & _
> >> " AND LogOutTime Is Null"
> >>
> >> Set db = CurrentDb
> >>
> >> With db
> >> .Execute strSQL, dbFailOnError
> >> If .RecordsAffected = 0 Then
> >> MsgBox "No records found"
> >> Else
> >> MsgBox "Records found and updated"
> >> End If
> >> End With
> >>
> >> Set db = Nothing
> >> '----- end of revised code #2 -----

>
> You'll get that message if the database engine doesn't recognize one of
> the names used in the SQL statement. I only guessed at "LogDate" as the
> name of the date field; is it "LogInDate", maybe, or some other name
> than I guessed? If so, you need to change the name used in building the
> SQL statement.
>
> Another possibility would be that you aren't running the query from
> Microsoft Access. If you run it from some other application, I don't
> think the Time() function will be recognized.
>
> --
> Dirk Goldgar, MS Access MVP
> www.datagnostics.com
>
> (please reply to the newsgroup)
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Date string problem in query string when posting back =?Utf-8?B?SnVsaWEgQg==?= Microsoft ASP .NET 5 29th Aug 2007 03:08 PM
how to make two references to one string that stay refered to the same string reguardless of the changing value in the string? Daniel Microsoft Dot NET 7 12th Nov 2004 09:08 AM
how to make two references to one string that stay refered to the same string reguardless of the changing value in the string? Daniel Microsoft C# .NET 10 3rd Nov 2004 03:26 PM
Searching for a unique charater in a string, vb Azazal Microsoft Excel Programming 2 13th Apr 2004 09:29 PM
Cannot create an object of type 'System.String[]' from its string representation 'String[] Array' for the 'Options' property. Hessam Microsoft C# .NET 0 8th Aug 2003 09:45 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:44 AM.