Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Access 2003 VBA Programmer's Reference
This is the forum to discuss the Wrox book Access 2003 VBA Programmer's Reference by Patricia Cardoza, Teresa Hennig, Graham Seach, Armen Stein; ISBN: 9780764559037
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Access 2003 VBA Programmer's Reference section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 14th, 2005, 09:03 AM
Authorized User
 
Join Date: May 2004
Location: montpellier, 34000, France.
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default somes questions

I have some questions concerning about the Access 2002.
In the Northwind sample, the form Employees contains the
Sub Form_Current()
………..‘The others lines
    and then the line
    Me![ImageFrame].Picture = fName
End sub

!!!This Property isn’t like any other control like combobox, textbox etc… I mean is it right that the control [ImageFrame].Picture search for the filename before. If this filename doesn’t exist it will not do the line Me![ImageFrame].Picture = FName above?


The Form_RecordExit doesn’t occur at any time

Other question
I try to enter a value to a date data type like this
When I type “29/2/2005” I have an error msg
but “29/2/05” give me another date “05/2/2029” or “31/4/05” give me “05/4/1931”

for these “29/2/2005” and “31/4/2005”, the Access’ OnError event catches them but “29/2/05” and “31/4/05” will be changed before the control’s BeforeUpdate event
I catch the control’s BeforeUpdate event in combining with the control.Undo but this occurs after the form’s OnError. So I have some wrong results after the undo method.
Can you show me a solution? Thank you.


Reply With Quote
  #2 (permalink)  
Old April 14th, 2005, 08:08 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Seattle, WA, .
Posts: 248
Thanks: 0
Thanked 1 Time in 1 Post
Default

If you set the image to a filename that doesn't exist, what do you think is going to happen? My bet would be that Access is going to report an error that the file could not be found. So I would say that you want to see if the file exists before you try to use it (your code snippit doesn't suggest that the file is checked first).

Clearly the date is being interpretted. I'm not sure why your dates are accepted in what appears to be YY/DD/MM format.

I would suggest that you not use the OnError event when the field the error is associated with is a date field but do your own editing in the BeforeUpdate event.

I've never used the OnError event of the form. Not sure why I would want to.

Randall J Weers
Membership Vice President
Pacific NorthWest Access Developers Group
http://www.pnwadg.org
Reply With Quote
  #3 (permalink)  
Old May 1st, 2005, 05:19 AM
Authorized User
 
Join Date: May 2004
Location: montpellier, 34000, France.
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

yes i have tried with the BeforeUpdate event to catch the text and test before it save to record but if you type a value of date like 29/2/05 this will be changed to 5/2/2029 and saved to the OldValue Property of this Control. then the BeforeUpdate event shows my msg and does the DoCmd.Undo to this Control but the OldValue now is 5/2/2029, not the original OldValue. thanks so much


Reply With Quote
  #4 (permalink)  
Old May 1st, 2005, 12:23 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Seattle, WA, .
Posts: 248
Thanks: 0
Thanked 1 Time in 1 Post
Default

Sorry, I didn't understand your explanation about what was happening with the BeforeUpdate and Undo.

Not that this matters to you and I'm sure this has something to do with my system's date format settings. But if I type 29/2/5 into a date field, I get:

DateField.OldValue = 2/5/2029
DateField.Value = 2/5/2029
DateField.Text = 29/2/5

I assume that means the when you use the BeforeUpdate event to validate the format, you should look at .Text to see and edit what the user typed.

The Undo does give crazy results. Why does Access set the OldValue to garbage? Must have something to do with the fact that Access is aware that the field is a date field? Whatever!!!

Sorry, but it looks like you'll have to do things the hard way. You could try this code in the module of the form:
Code:
Dim varSampleFromDate As Variant
Dim blnSampleFromDateBad As Boolean

Public Function MyDateValidation(pvarDate As Variant) As Boolean
' NOTE: Undo won't work if validation occurs in the BeforeUpdate event
'       because the OldValue of the field gets set according to the bad
'       date that was entered.
If IsNull(pvarDate) Then
    MyDateValidation = True
Else
    If pvarDate = "29/2/5" Then ' validate date format
        MyDateValidation = False
    Else
        MyDateValidation = True
    End If
End If
End Function

Private Sub SampleFromDate_BeforeUpdate(Cancel As Integer)
blnSampleFromDateBad = MyDateValidation(Me.SampleFromDate)
End Sub

Private Sub SampleFromDate_Enter()
blnSampleFromDateBad = False
varSampleFromDate = Me.SampleFromDate
End Sub

Private Sub SampleFromDate_Exit(Cancel As Integer)
If blnSampleFromDateBad Then
    blnSampleFromDateBad = False
    Me.SampleFromDate = varSampleFromDate
    Cancel = True
End If
End Sub
Of course, depending on how important that date is, you could just let the bad date be recorded. Hopefully, users will get used entering dates properly.
Reply With Quote
  #5 (permalink)  
Old May 1st, 2005, 12:29 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Seattle, WA, .
Posts: 248
Thanks: 0
Thanked 1 Time in 1 Post
Default

Come to think of it, you could just put the date validation in Exit, then you wouldn't need blnSampleFromDateBad or the BeforeUpdate event.

Change the Exit event to:
Code:
Private Sub SampleFromDate_Exit(Cancel As Integer)
If Not MyDateValidation(Me.SampleFromDate) Then
    Me.SampleFromDate = varSampleFromDate
    Cancel = True
End If
End Sub
Reply With Quote
  #6 (permalink)  
Old May 8th, 2005, 04:31 AM
Authorized User
 
Join Date: May 2004
Location: montpellier, 34000, France.
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks for your help. this made me some experiences. but i have found the reason why for the problems (29/2/05) of date type control. finally, you could turn the autocorrect property of the controls who data type is date, to NO then it is solved.

by the way, if you can tell me why when i try to insert an expression to a textbox control on report. this doesn't work correctly. i tried also to create an unbound textbox then attach this =trim([address]) but this shows #error? or #name? on normal view or printpreview

need your help
VB

Reply With Quote
  #7 (permalink)  
Old May 8th, 2005, 09:54 AM
Friend of Wrox
 
Join Date: Nov 2004
Location: Seattle, WA, .
Posts: 248
Thanks: 0
Thanked 1 Time in 1 Post
Default

Didn't think of that autocorrect. That was a good find.

Since the text box question isn't related to the book, you should go ahead and ask it on the following forum:

http://p2p.wrox.com/forum.asp?FORUM_ID=5
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
.NET Interview Questions, C# Interview Questions, dotnetuncle .NET Framework 2.0 4 June 22nd, 2019 07:03 AM
C++ questions jam93 C++ Programming 1 August 19th, 2007 10:39 PM
two questions reverand Excel VBA 2 December 5th, 2005 06:33 AM
C# questions zhenliu C# 1 April 15th, 2004 09:18 AM
questions anshul Javascript How-To 1 April 12th, 2004 07:29 AM



All times are GMT -4. The time now is 04:51 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.