A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

between and



 
 
Thread Tools Display Modes
  #1  
Old December 14th, 2006, 05:26 PM posted to microsoft.public.access.forms
ielmrani via AccessMonster.com
external usenet poster
 
Posts: 69
Default between and

Can anyone tell me why this code is not working:

Private Sub Form_Open(Cancel As Integer)
If Me.[Inception_Date] between #1/1/2006# And #12/31/2006# Then
txtCode = "6I"
Else
If Me.[Inception_Date] between #1/1/2007# And #12/31/2007# Then
txtCode = "7I"
End If
End If

End Sub

It does like the word Between.

Thanks in advance

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/200612/1

  #2  
Old December 14th, 2006, 05:48 PM posted to microsoft.public.access.forms
fredg
external usenet poster
 
Posts: 4,386
Default between and

On Thu, 14 Dec 2006 17:26:53 GMT, ielmrani via AccessMonster.com
wrote:

Can anyone tell me why this code is not working:

Private Sub Form_Open(Cancel As Integer)
If Me.[Inception_Date] between #1/1/2006# And #12/31/2006# Then
txtCode = "6I"
Else
If Me.[Inception_Date] between #1/1/2007# And #12/31/2007# Then
txtCode = "7I"
End If
End If

End Sub

It does like the word Between.

Thanks in advance



If Me.[Inception_Date] = #1/1/2006# And Me![Inception_Date] =
#12/31/2006# Then
txtCode = "6I"
Else
If Me.[Inception_Date] = #1/1/2007# And Me![Inception_Date] =
#12/31/2007# Then
txtCode = "7I"

--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
  #3  
Old December 14th, 2006, 05:53 PM posted to microsoft.public.access.forms
Douglas J. Steele
external usenet poster
 
Posts: 9,313
Default between and

I don't believe you can use Between in VBA.

Try:

Private Sub Form_Open(Cancel As Integer)

If Me.[Inception_Date] = #1/1/2006# And _
Me.[Inception_Date] = #12/31/2006# Then
txtCode = "6I"
Else
If Me.[Inception_Date] = #1/1/2007# And _
Me.[Inception_Date] = #12/31/2007# Then
txtCode = "7I"
End If
End If

End Sub

Alternatively, you could use

Private Sub Form_Open(Cancel As Integer)

If Year(Me.[Inception_Date]) = 2006 Then
txtCode = "6I"
Else
If Year(Me.[Inception_Date]) = 2007 Then
txtCode = "7I"
End If
End If

End Sub

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"ielmrani via AccessMonster.com" u21259@uwe wrote in message
news:6ac1f3f540207@uwe...
Can anyone tell me why this code is not working:

Private Sub Form_Open(Cancel As Integer)
If Me.[Inception_Date] between #1/1/2006# And #12/31/2006# Then
txtCode = "6I"
Else
If Me.[Inception_Date] between #1/1/2007# And #12/31/2007# Then
txtCode = "7I"
End If
End If

End Sub

It does like the word Between.

Thanks in advance

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/200612/1



  #4  
Old December 14th, 2006, 06:03 PM posted to microsoft.public.access.forms
missinglinq via AccessMonster.com
external usenet poster
 
Posts: 545
Default between and

BETWEEN is not valid VBA code, nor is the pound signs surrounding the dates;
they're only used in SQL statements. You need to use a structure similar to
this.

If (Me.[Inception_Date] ="1/1/2006") And (Me.[Inception_Date] =
"12/31/2006") Then
txtCode.Value = "6I"
ElseIf (Me.[Inception_Date] ="1/1/2007") And (Me.[Inception_Date] =
"12/31/2007") Then
txtCode.Value = "7I"
End If

This structure is sound, but I'm a little fuzzy on comparing dates (Me.
[Inception_Date] ="1/1/2006"); I don't have access to Access right now, so I
can't testdrive this, but I think this is correct, and it's certainly a
pointer in the right direction.

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/200612/1

  #5  
Old December 14th, 2006, 07:05 PM posted to microsoft.public.access.forms
ielmrani via AccessMonster.com
external usenet poster
 
Posts: 69
Default between and

thank you very much everyone

missinglinq wrote:
BETWEEN is not valid VBA code, nor is the pound signs surrounding the dates;
they're only used in SQL statements. You need to use a structure similar to
this.

If (Me.[Inception_Date] ="1/1/2006") And (Me.[Inception_Date] =
"12/31/2006") Then
txtCode.Value = "6I"
ElseIf (Me.[Inception_Date] ="1/1/2007") And (Me.[Inception_Date] =
"12/31/2007") Then
txtCode.Value = "7I"
End If

This structure is sound, but I'm a little fuzzy on comparing dates (Me.
[Inception_Date] ="1/1/2006"); I don't have access to Access right now, so I
can't testdrive this, but I think this is correct, and it's certainly a
pointer in the right direction.


--
Message posted via http://www.accessmonster.com

 




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


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


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.