473,387 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Ensuring non-null values in subdatasheet on record exit

Per
Hi,

I have a problem that I can't figure out. I have a database application
to keep track of boxes that contain files. For data entry, I have a
form with a main form section for the box-specific data (box
description etc), and a subform for entering details on each file
that's in the box (type, subtype etc). The subform is in a datasheet
form, with one record on each row.

Some of the subform fields are filled in using drop-downs, which have a
query on underlying tables as recordsource. Some of the fields (not
all) in the subform are required, ie Null is not allowed.

I want to check that all these required fields are filled in by the
user when he/she moves on to the next record in the subdatasheet. I
can't figure out how to do this. I have tried using the OnCurrent event
for the subform, cloning the current recordset, going back to the
previous record, and checking the values of these fields. But this
doesn't seem to work, it gets stuck in a loop betwen the last record
and the current record. Here's some code:
---
>From subform code:
Public currfile As Long
Public lastfile As Long
Public currbox As Long
Public lastbox As Long

Sub UpdateCurrentFile()
If Not IsNull(Me.FileID) And currfile <Me.FileID And currfile <0
Then
lastfile = currfile
End If
If Not IsNull(Me.FileID) Then currfile = Me.FileID

If Not IsNull(Me.BoxID) And currbox <Me.BoxID And currbox <0 Then
lastbox = currbox
End If
If Not IsNull(Me.BoxID) Then currbox = Me.BoxID
End Sub
---
Private Sub Form_Current()
Dim strSQL As String
Dim choice As Integer
Dim rst As Recordset

UpdateCurrentFile

If lastfile <0 Then
Set rst = Me.RecordsetClone
rst.FindFirst "FileID=" & lastfile
Me.Bookmark = rst.Bookmark

If IsNull(Me.DocType) Then
MsgBox "DocType is required. Please select from drop-down box."
Me.DocType.SetFocus
Me.DocType.Dropdown
ElseIf IsNull(Me.MeetingType) And Me.DocType <"Election" Then
MsgBox "MeetingType is required for this DocType. Please select
from drop-down box."
Me.MeetingType.SetFocus
Me.MeetingType.Dropdown
ElseIf IsNull(Me.SubType) Then
MsgBox "SubType is required. Please select from drop-down box."
Me.SubType.SetFocus
Me.SubType.Dropdown
ElseIf IsNull(Me.DocumentDate) Then
MsgBox "DocumentDate is required. Please select from drop-down
box."
Me.DocumentDate.SetFocus
Else
Me.Bookmark = Me.RecordsetClone.Bookmark
End If

rst.Close
Set rst = Nothing
Me.Refresh
End If
End Sub

I am using Access 2003, so the Access 2002 On Record Exit doesn't seem
to be avaiable. Any ideas?

Thanks for your help.

/Per

Aug 18 '06 #1
1 2338
On 18 Aug 2006 11:20:08 -0700, "Per" <pa**********@gmail.comwrote:

The proper event to perform the check is Form_BeforeUpdate of the
subform.
There is no need for a RecordsetClone; just access the values in the
various controls.

-Tom.

>Hi,

I have a problem that I can't figure out. I have a database application
to keep track of boxes that contain files. For data entry, I have a
form with a main form section for the box-specific data (box
description etc), and a subform for entering details on each file
that's in the box (type, subtype etc). The subform is in a datasheet
form, with one record on each row.

Some of the subform fields are filled in using drop-downs, which have a
query on underlying tables as recordsource. Some of the fields (not
all) in the subform are required, ie Null is not allowed.

I want to check that all these required fields are filled in by the
user when he/she moves on to the next record in the subdatasheet. I
can't figure out how to do this. I have tried using the OnCurrent event
for the subform, cloning the current recordset, going back to the
previous record, and checking the values of these fields. But this
doesn't seem to work, it gets stuck in a loop betwen the last record
and the current record. Here's some code:
---
>>From subform code:

Public currfile As Long
Public lastfile As Long
Public currbox As Long
Public lastbox As Long

Sub UpdateCurrentFile()
If Not IsNull(Me.FileID) And currfile <Me.FileID And currfile <0
Then
lastfile = currfile
End If
If Not IsNull(Me.FileID) Then currfile = Me.FileID

If Not IsNull(Me.BoxID) And currbox <Me.BoxID And currbox <0 Then
lastbox = currbox
End If
If Not IsNull(Me.BoxID) Then currbox = Me.BoxID
End Sub
---
Private Sub Form_Current()
Dim strSQL As String
Dim choice As Integer
Dim rst As Recordset

UpdateCurrentFile

If lastfile <0 Then
Set rst = Me.RecordsetClone
rst.FindFirst "FileID=" & lastfile
Me.Bookmark = rst.Bookmark

If IsNull(Me.DocType) Then
MsgBox "DocType is required. Please select from drop-down box."
Me.DocType.SetFocus
Me.DocType.Dropdown
ElseIf IsNull(Me.MeetingType) And Me.DocType <"Election" Then
MsgBox "MeetingType is required for this DocType. Please select
from drop-down box."
Me.MeetingType.SetFocus
Me.MeetingType.Dropdown
ElseIf IsNull(Me.SubType) Then
MsgBox "SubType is required. Please select from drop-down box."
Me.SubType.SetFocus
Me.SubType.Dropdown
ElseIf IsNull(Me.DocumentDate) Then
MsgBox "DocumentDate is required. Please select from drop-down
box."
Me.DocumentDate.SetFocus
Else
Me.Bookmark = Me.RecordsetClone.Bookmark
End If

rst.Close
Set rst = Nothing
Me.Refresh
End If
End Sub

I am using Access 2003, so the Access 2002 On Record Exit doesn't seem
to be avaiable. Any ideas?

Thanks for your help.

/Per
Aug 19 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: klaus triendl | last post by:
hi, recently i discovered a memory leak in our code; after some investigation i could reduce it to the following problem: return objects of functions are handled as temporary objects, hence...
3
by: Mario | last post by:
Hello, I couldn't find a solution to the following problem (tried google and dejanews), maybe I'm using the wrong keywords? Is there a way to open a file (a linux fifo pipe actually) in...
2
by: frs | last post by:
How can I get an 'always non-const equivalent' for the type "T" in the following example? Is there something like a 'non_const_cast' as in the code fragment below? template<typename T> class A...
3
by: Peter Hardy | last post by:
Hi guys, Sorry for the cross-post but I got no response in the asp.net newsgroup. I am trying to develop a mini e-learning application where the user provides content for each page....
32
by: Adrian Herscu | last post by:
Hi all, In which circumstances it is appropriate to declare methods as non-virtual? Thanx, Adrian.
0
by: Peter Hardy | last post by:
Hi guys, I am trying to develop a mini e-learning application where the user provides content for each page. Eventually, I'd like to shift to using templates but at the moment the users is just...
14
by: ToddLMorgan | last post by:
Summary: How should multiple (related) projects be arranged (structured) and configured so that the following is possible: o Sharing common code (one of the projects would be a "common" project...
1
by: Chris Curvey | last post by:
Hey all, I'm trying to write something that will "fail fast" if one of my users gives me non-latin-1 characters. So I tried this: u'\x80' I would have thought that that should have raised...
399
by: =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= | last post by:
PEP 1 specifies that PEP authors need to collect feedback from the community. As the author of PEP 3131, I'd like to encourage comments to the PEP included below, either here (comp.lang.python), or...
3
by: Josh Paetzel | last post by:
Is there a way to ensure that GNU readline isn't used (even though support may have been compiled in?). I'm experiencing a licensing problem, I'd like to use the "cmd" module, for example, but my...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.