Load Form on Specific Date

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I asked for help on VB code that would display a specific date for a form I
was workingwith. (Thanks Dirk!) It worked excellent. However, my customer
wants it to display the previous days date. Below is an example of the code
Dirk provided:

Private Sub Form_Load()
With Me.RecordsetClone
If .RecordCount > 0 Then
.FindFirst "[DutyDate] = Date()"
If .NoMatch Then
.MoveLast
End If
Me.Bookmark = .Bookmark
End If
End With
End Sub

Can anyone suggest how I could adjust the code so that when the form loads
it displays yesterdays date? I tried to insert the following but got an error
when I tried to debug:
If .RecordCount > 0 Then
.FindFirst "[DutyDate] = DateAdd("d',-1,Date())"
If .NoMatch Then
.MoveLast

Any help would be greatly appreciated.
 
It looks like your speech marks are getting in the way

your code

..FindFirst "[DutyDate] = DateAdd("d',-1,Date())"


firstly the "d' is wrong you have to use " not ' in the dateadd function

I don't khow if the next thing is a problem, but the the first speech mark
in the dateAdd function maybe causing problems.

so if the problem is not solved via method one,

create a variable

dim myDate as date

myDate = DateAdd("d",-1,Date())

..FindFirst "[DutyDate] =" & mydate
 
Alex, Thank you for the response. I typed the following code into the on load
event, but now it just goes to the last record in the table....did I enter it
wrong?

Private Sub Form_Load()
Dim myDate As Date

myDate = DateAdd("d", -1, Date)
With Me.RecordsetClone
If .RecordCount > 0 Then
.FindFirst "[DutyDate] =" & myDate
If .NoMatch Then
.MoveLast
End If
Me.Bookmark = .Bookmark
End If
End With
End Sub

Thx...Antonio

Alex White MCDBA MCSE said:
It looks like your speech marks are getting in the way

your code

..FindFirst "[DutyDate] = DateAdd("d',-1,Date())"


firstly the "d' is wrong you have to use " not ' in the dateadd function

I don't khow if the next thing is a problem, but the the first speech mark
in the dateAdd function maybe causing problems.

so if the problem is not solved via method one,

create a variable

dim myDate as date

myDate = DateAdd("d",-1,Date())

..FindFirst "[DutyDate] =" & mydate


--
Regards

Alex White MCDBA MCSE
http://www.intralan.co.uk

Antonio said:
I asked for help on VB code that would display a specific date for a form I
was workingwith. (Thanks Dirk!) It worked excellent. However, my customer
wants it to display the previous days date. Below is an example of the
code
Dirk provided:

Private Sub Form_Load()
With Me.RecordsetClone
If .RecordCount > 0 Then
.FindFirst "[DutyDate] = Date()"
If .NoMatch Then
.MoveLast
End If
Me.Bookmark = .Bookmark
End If
End With
End Sub

Can anyone suggest how I could adjust the code so that when the form loads
it displays yesterdays date? I tried to insert the following but got an
error
when I tried to debug:
If .RecordCount > 0 Then
.FindFirst "[DutyDate] = DateAdd("d',-1,Date())"
If .NoMatch Then
.MoveLast

Any help would be greatly appreciated.
 
Sorry missed the #'s


..FindFirst "[DutyDate] =#" & myDate & "#"


--
Regards

Alex White MCDBA MCSE
http://www.intralan.co.uk

Antonio said:
Alex, Thank you for the response. I typed the following code into the on
load
event, but now it just goes to the last record in the table....did I enter
it
wrong?

Private Sub Form_Load()
Dim myDate As Date

myDate = DateAdd("d", -1, Date)
With Me.RecordsetClone
If .RecordCount > 0 Then
.FindFirst "[DutyDate] =" & myDate
If .NoMatch Then
.MoveLast
End If
Me.Bookmark = .Bookmark
End If
End With
End Sub

Thx...Antonio

Alex White MCDBA MCSE said:
It looks like your speech marks are getting in the way

your code

..FindFirst "[DutyDate] = DateAdd("d',-1,Date())"


firstly the "d' is wrong you have to use " not ' in the dateadd function

I don't khow if the next thing is a problem, but the the first speech
mark
in the dateAdd function maybe causing problems.

so if the problem is not solved via method one,

create a variable

dim myDate as date

myDate = DateAdd("d",-1,Date())

..FindFirst "[DutyDate] =" & mydate


--
Regards

Alex White MCDBA MCSE
http://www.intralan.co.uk

Antonio said:
I asked for help on VB code that would display a specific date for a
form I
was workingwith. (Thanks Dirk!) It worked excellent. However, my
customer
wants it to display the previous days date. Below is an example of the
code
Dirk provided:

Private Sub Form_Load()
With Me.RecordsetClone
If .RecordCount > 0 Then
.FindFirst "[DutyDate] = Date()"
If .NoMatch Then
.MoveLast
End If
Me.Bookmark = .Bookmark
End If
End With
End Sub

Can anyone suggest how I could adjust the code so that when the form
loads
it displays yesterdays date? I tried to insert the following but got an
error
when I tried to debug:
If .RecordCount > 0 Then
.FindFirst "[DutyDate] = DateAdd("d',-1,Date())"
If .NoMatch Then
.MoveLast

Any help would be greatly appreciated.
 
I made the changes....but I still have the same issue....the form loads on
the last record inthe table... Here is what I typed in:
Private Sub Form_Load()
Dim myDate As Date

myDate = DateAdd("d", -1, Date)
With Me.RecordsetClone
If .RecordCount > 0 Then
.FindFirst "[DutyDate] = #" & myDate & "#"
If .NoMatch Then
.MoveLast
End If
Me.Bookmark = .Bookmark
End If
End With
End Sub

Antonio


Alex White MCDBA MCSE said:
Sorry missed the #'s


..FindFirst "[DutyDate] =#" & myDate & "#"


--
Regards

Alex White MCDBA MCSE
http://www.intralan.co.uk

Antonio said:
Alex, Thank you for the response. I typed the following code into the on
load
event, but now it just goes to the last record in the table....did I enter
it
wrong?

Private Sub Form_Load()
Dim myDate As Date

myDate = DateAdd("d", -1, Date)
With Me.RecordsetClone
If .RecordCount > 0 Then
.FindFirst "[DutyDate] =" & myDate
If .NoMatch Then
.MoveLast
End If
Me.Bookmark = .Bookmark
End If
End With
End Sub

Thx...Antonio

Alex White MCDBA MCSE said:
It looks like your speech marks are getting in the way

your code

..FindFirst "[DutyDate] = DateAdd("d',-1,Date())"


firstly the "d' is wrong you have to use " not ' in the dateadd function

I don't khow if the next thing is a problem, but the the first speech
mark
in the dateAdd function maybe causing problems.

so if the problem is not solved via method one,

create a variable

dim myDate as date

myDate = DateAdd("d",-1,Date())

..FindFirst "[DutyDate] =" & mydate


--
Regards

Alex White MCDBA MCSE
http://www.intralan.co.uk

I asked for help on VB code that would display a specific date for a
form I
was workingwith. (Thanks Dirk!) It worked excellent. However, my
customer
wants it to display the previous days date. Below is an example of the
code
Dirk provided:

Private Sub Form_Load()
With Me.RecordsetClone
If .RecordCount > 0 Then
.FindFirst "[DutyDate] = Date()"
If .NoMatch Then
.MoveLast
End If
Me.Bookmark = .Bookmark
End If
End With
End Sub

Can anyone suggest how I could adjust the code so that when the form
loads
it displays yesterdays date? I tried to insert the following but got an
error
when I tried to debug:
If .RecordCount > 0 Then
.FindFirst "[DutyDate] = DateAdd("d',-1,Date())"
If .NoMatch Then
.MoveLast

Any help would be greatly appreciated.
 
It must be a date formatting issue,

..FindFirst "[DutyDate] = " & Format(myDate, "\#yyyy\-mm\-dd\#")


--
Regards

Alex White MCDBA MCSE
http://www.intralan.co.uk

Antonio said:
I made the changes....but I still have the same issue....the form loads on
the last record inthe table... Here is what I typed in:
Private Sub Form_Load()
Dim myDate As Date

myDate = DateAdd("d", -1, Date)
With Me.RecordsetClone
If .RecordCount > 0 Then
.FindFirst "[DutyDate] = #" & myDate & "#"
If .NoMatch Then
.MoveLast
End If
Me.Bookmark = .Bookmark
End If
End With
End Sub

Antonio


Alex White MCDBA MCSE said:
Sorry missed the #'s


..FindFirst "[DutyDate] =#" & myDate & "#"


--
Regards

Alex White MCDBA MCSE
http://www.intralan.co.uk

Antonio said:
Alex, Thank you for the response. I typed the following code into the
on
load
event, but now it just goes to the last record in the table....did I
enter
it
wrong?

Private Sub Form_Load()
Dim myDate As Date

myDate = DateAdd("d", -1, Date)
With Me.RecordsetClone
If .RecordCount > 0 Then
.FindFirst "[DutyDate] =" & myDate
If .NoMatch Then
.MoveLast
End If
Me.Bookmark = .Bookmark
End If
End With
End Sub

Thx...Antonio

:

It looks like your speech marks are getting in the way

your code

..FindFirst "[DutyDate] = DateAdd("d',-1,Date())"


firstly the "d' is wrong you have to use " not ' in the dateadd
function

I don't khow if the next thing is a problem, but the the first speech
mark
in the dateAdd function maybe causing problems.

so if the problem is not solved via method one,

create a variable

dim myDate as date

myDate = DateAdd("d",-1,Date())

..FindFirst "[DutyDate] =" & mydate


--
Regards

Alex White MCDBA MCSE
http://www.intralan.co.uk

I asked for help on VB code that would display a specific date for a
form I
was workingwith. (Thanks Dirk!) It worked excellent. However, my
customer
wants it to display the previous days date. Below is an example of
the
code
Dirk provided:

Private Sub Form_Load()
With Me.RecordsetClone
If .RecordCount > 0 Then
.FindFirst "[DutyDate] = Date()"
If .NoMatch Then
.MoveLast
End If
Me.Bookmark = .Bookmark
End If
End With
End Sub

Can anyone suggest how I could adjust the code so that when the form
loads
it displays yesterdays date? I tried to insert the following but got
an
error
when I tried to debug:
If .RecordCount > 0 Then
.FindFirst "[DutyDate] = DateAdd("d',-1,Date())"
If .NoMatch Then
.MoveLast

Any help would be greatly appreciated.
 
have you also tried

..FindFirst "[DutyDate] = Date()-1"


--
Regards

Alex White MCDBA MCSE
http://www.intralan.co.uk

Antonio said:
I made the changes....but I still have the same issue....the form loads on
the last record inthe table... Here is what I typed in:
Private Sub Form_Load()
Dim myDate As Date

myDate = DateAdd("d", -1, Date)
With Me.RecordsetClone
If .RecordCount > 0 Then
.FindFirst "[DutyDate] = #" & myDate & "#"
If .NoMatch Then
.MoveLast
End If
Me.Bookmark = .Bookmark
End If
End With
End Sub

Antonio


Alex White MCDBA MCSE said:
Sorry missed the #'s


..FindFirst "[DutyDate] =#" & myDate & "#"


--
Regards

Alex White MCDBA MCSE
http://www.intralan.co.uk

Antonio said:
Alex, Thank you for the response. I typed the following code into the
on
load
event, but now it just goes to the last record in the table....did I
enter
it
wrong?

Private Sub Form_Load()
Dim myDate As Date

myDate = DateAdd("d", -1, Date)
With Me.RecordsetClone
If .RecordCount > 0 Then
.FindFirst "[DutyDate] =" & myDate
If .NoMatch Then
.MoveLast
End If
Me.Bookmark = .Bookmark
End If
End With
End Sub

Thx...Antonio

:

It looks like your speech marks are getting in the way

your code

..FindFirst "[DutyDate] = DateAdd("d',-1,Date())"


firstly the "d' is wrong you have to use " not ' in the dateadd
function

I don't khow if the next thing is a problem, but the the first speech
mark
in the dateAdd function maybe causing problems.

so if the problem is not solved via method one,

create a variable

dim myDate as date

myDate = DateAdd("d",-1,Date())

..FindFirst "[DutyDate] =" & mydate


--
Regards

Alex White MCDBA MCSE
http://www.intralan.co.uk

I asked for help on VB code that would display a specific date for a
form I
was workingwith. (Thanks Dirk!) It worked excellent. However, my
customer
wants it to display the previous days date. Below is an example of
the
code
Dirk provided:

Private Sub Form_Load()
With Me.RecordsetClone
If .RecordCount > 0 Then
.FindFirst "[DutyDate] = Date()"
If .NoMatch Then
.MoveLast
End If
Me.Bookmark = .Bookmark
End If
End With
End Sub

Can anyone suggest how I could adjust the code so that when the form
loads
it displays yesterdays date? I tried to insert the following but got
an
error
when I tried to debug:
If .RecordCount > 0 Then
.FindFirst "[DutyDate] = DateAdd("d',-1,Date())"
If .NoMatch Then
.MoveLast

Any help would be greatly appreciated.
 
Im sorry to say its still going to the last record....(I appreciate all the
effort your putting in this) Here is what I typed in:

Private Sub Form_Load()
Dim myDate As Date

myDate = DateAdd("d", -1, Date)
With Me.RecordsetClone
If .RecordCount > 0 Then
.FindFirst "[DutyDate] = " & Format(myDate, "\#yyyy\-mm\-dd\#")
If .NoMatch Then
.MoveLast
End If
Me.Bookmark = .Bookmark
End If
End With
End Sub

In the table the format for the field is "Short Date". On the form it
displays in "Long Date" (Tuesday, June 14,1994). I tried changing the format
of the field on the form to "Short Date", but it didn't change anything...

Antonio

Alex White MCDBA MCSE said:
It must be a date formatting issue,

..FindFirst "[DutyDate] = " & Format(myDate, "\#yyyy\-mm\-dd\#")


--
Regards

Alex White MCDBA MCSE
http://www.intralan.co.uk

Antonio said:
I made the changes....but I still have the same issue....the form loads on
the last record inthe table... Here is what I typed in:
Private Sub Form_Load()
Dim myDate As Date

myDate = DateAdd("d", -1, Date)
With Me.RecordsetClone
If .RecordCount > 0 Then
.FindFirst "[DutyDate] = #" & myDate & "#"
If .NoMatch Then
.MoveLast
End If
Me.Bookmark = .Bookmark
End If
End With
End Sub

Antonio


Alex White MCDBA MCSE said:
Sorry missed the #'s


..FindFirst "[DutyDate] =#" & myDate & "#"


--
Regards

Alex White MCDBA MCSE
http://www.intralan.co.uk

Alex, Thank you for the response. I typed the following code into the
on
load
event, but now it just goes to the last record in the table....did I
enter
it
wrong?

Private Sub Form_Load()
Dim myDate As Date

myDate = DateAdd("d", -1, Date)
With Me.RecordsetClone
If .RecordCount > 0 Then
.FindFirst "[DutyDate] =" & myDate
If .NoMatch Then
.MoveLast
End If
Me.Bookmark = .Bookmark
End If
End With
End Sub

Thx...Antonio

:

It looks like your speech marks are getting in the way

your code

..FindFirst "[DutyDate] = DateAdd("d',-1,Date())"


firstly the "d' is wrong you have to use " not ' in the dateadd
function

I don't khow if the next thing is a problem, but the the first speech
mark
in the dateAdd function maybe causing problems.

so if the problem is not solved via method one,

create a variable

dim myDate as date

myDate = DateAdd("d",-1,Date())

..FindFirst "[DutyDate] =" & mydate


--
Regards

Alex White MCDBA MCSE
http://www.intralan.co.uk

I asked for help on VB code that would display a specific date for a
form I
was workingwith. (Thanks Dirk!) It worked excellent. However, my
customer
wants it to display the previous days date. Below is an example of
the
code
Dirk provided:

Private Sub Form_Load()
With Me.RecordsetClone
If .RecordCount > 0 Then
.FindFirst "[DutyDate] = Date()"
If .NoMatch Then
.MoveLast
End If
Me.Bookmark = .Bookmark
End If
End With
End Sub

Can anyone suggest how I could adjust the code so that when the form
loads
it displays yesterdays date? I tried to insert the following but got
an
error
when I tried to debug:
If .RecordCount > 0 Then
.FindFirst "[DutyDate] = DateAdd("d',-1,Date())"
If .NoMatch Then
.MoveLast

Any help would be greatly appreciated.
 
That WORKED!!! Thank you So SO much Alex. I appreciate your help SO much.
Thank you Thank you Thank you.
Antonio

Alex White MCDBA MCSE said:
have you also tried

..FindFirst "[DutyDate] = Date()-1"


--
Regards

Alex White MCDBA MCSE
http://www.intralan.co.uk

Antonio said:
I made the changes....but I still have the same issue....the form loads on
the last record inthe table... Here is what I typed in:
Private Sub Form_Load()
Dim myDate As Date

myDate = DateAdd("d", -1, Date)
With Me.RecordsetClone
If .RecordCount > 0 Then
.FindFirst "[DutyDate] = #" & myDate & "#"
If .NoMatch Then
.MoveLast
End If
Me.Bookmark = .Bookmark
End If
End With
End Sub

Antonio


Alex White MCDBA MCSE said:
Sorry missed the #'s


..FindFirst "[DutyDate] =#" & myDate & "#"


--
Regards

Alex White MCDBA MCSE
http://www.intralan.co.uk

Alex, Thank you for the response. I typed the following code into the
on
load
event, but now it just goes to the last record in the table....did I
enter
it
wrong?

Private Sub Form_Load()
Dim myDate As Date

myDate = DateAdd("d", -1, Date)
With Me.RecordsetClone
If .RecordCount > 0 Then
.FindFirst "[DutyDate] =" & myDate
If .NoMatch Then
.MoveLast
End If
Me.Bookmark = .Bookmark
End If
End With
End Sub

Thx...Antonio

:

It looks like your speech marks are getting in the way

your code

..FindFirst "[DutyDate] = DateAdd("d',-1,Date())"


firstly the "d' is wrong you have to use " not ' in the dateadd
function

I don't khow if the next thing is a problem, but the the first speech
mark
in the dateAdd function maybe causing problems.

so if the problem is not solved via method one,

create a variable

dim myDate as date

myDate = DateAdd("d",-1,Date())

..FindFirst "[DutyDate] =" & mydate


--
Regards

Alex White MCDBA MCSE
http://www.intralan.co.uk

I asked for help on VB code that would display a specific date for a
form I
was workingwith. (Thanks Dirk!) It worked excellent. However, my
customer
wants it to display the previous days date. Below is an example of
the
code
Dirk provided:

Private Sub Form_Load()
With Me.RecordsetClone
If .RecordCount > 0 Then
.FindFirst "[DutyDate] = Date()"
If .NoMatch Then
.MoveLast
End If
Me.Bookmark = .Bookmark
End If
End With
End Sub

Can anyone suggest how I could adjust the code so that when the form
loads
it displays yesterdays date? I tried to insert the following but got
an
error
when I tried to debug:
If .RecordCount > 0 Then
.FindFirst "[DutyDate] = DateAdd("d',-1,Date())"
If .NoMatch Then
.MoveLast

Any help would be greatly appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top