473,750 Members | 2,292 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to check if subform is dirty

Rey
Howdy all.
Appreciate your help with several problems I'm having:

I'm trying to determine if the Visit subform (subformVisits) has a new
record or been changed, i.e. dirty. The form that contains the subform is
named Clients.

I have this code in the Add Client btn:
If Forms!Clients.s ubformVisits!Vi sitDirty = True Then
MsgBox "Visit subform is dirty!"
Else
MsgBox "problems. subform not dirty"
End If
But it displays err "applicatio n defined or object defined error."

The field VisitDirty is an unbound & not visible field with a True/False
format in the details section of subformVisits. Its code is:

Private Sub VisitDirty_Afte rUpdate()
' to see if the subform is "dirty", i.e. has changed or new record
If Me.Dirty Then
Me.VisitDirty = True
End If

End Sub

The reason for the unbound VisitDirty field is that I was having a devil of
a time trying to check if the subform was dirty. Probably didn't have the
syntax correct but tried setting a form var below but also had errs. Even
tried going to the control level but no success.

SET frmClient = Forms!Clients.s ubformVISITs

All the above is as the result of a test that caused an err...

The user enters a new record in the Visit subfrom and has tabbed thru the
fields to the DateEntered field into which the current system date is
entered if a new record.

At this point, the DateEntered field is highlighted. If the user - me - then
clicks on the Add Client button instead of the Save button which could/will
happen, I want to save the record in the subform, then move away from the
Dateentered field of the subform to the first name field before calling for
a new record in the Client form using DoCmd.GoToRecor d , , acNewRec

If the cursor is in the DateEntered field when the new record is created
then the current date is entered to the field but an err will soon display
because there is no new client number (autonumber) to insert into the Visit
table clientnum field.

Guess I need to better understand the Access event model among other things.
Using Access97 and both the client and subformVisit forms are bound to the
Clients and Visits table, respectively.

BTW, what is the difference between using the bang (!) and the dot (.) when
referencing a form as in
Forms!Clients!s ubformVisits and Forms!Clients.s ubformVisit.

Thanks in advance for your help/suggestions,

Rey
Nov 12 '05 #1
15 24866

"Rey" <re********@cox .net> skrev i melding
news:_hWjb.2941 3$gi2.21984@fed 1read01...
Howdy all.
Appreciate your help with several problems I'm having:


Try this code in subform on current event.

Sigurd
Private Sub Form_Current()
Dim rs As Recordset

Set rs = RecordsetClone
If rs.RecordCount = 0 Then
MsgBox "no records"
Else
MsgBox rs.RecordCount & " records"
End If

End Sub
Nov 12 '05 #2
Sigurd & All,
If you open a recordset to check for record count, then don't you have to
include
rs.MoveLast before checking rs.RecordCount?
Fred Zuckerman
San Diego, CA, USA
"Sigurd Bruteig" <s-********@online .no> wrote in message
news:Ul******** ***********@new s4.e.nsc.no...

"Rey" <re********@cox .net> skrev i melding
news:_hWjb.2941 3$gi2.21984@fed 1read01...
Howdy all.
Appreciate your help with several problems I'm having:


Try this code in subform on current event.

Sigurd
Private Sub Form_Current()
Dim rs As Recordset

Set rs = RecordsetClone
If rs.RecordCount = 0 Then
MsgBox "no records"
Else
MsgBox rs.RecordCount & " records"
End If

End Sub

Nov 12 '05 #3

"Fred Zuckerman" <Zu********@sbc global.net> skrev i melding
news:PA******** ********@newssv r25.news.prodig y.com...
Sigurd & All,
If you open a recordset to check for record count, then don't you have to
include
rs.MoveLast before checking rs.RecordCount?
Fred Zuckerman
San Diego, CA, USA


No, this code works great as is.

Sigurd
Nov 12 '05 #4
>> Sigurd & All,
If you open a recordset to check for record count, then don't you have to
include rs.MoveLast before checking rs.RecordCount?
Fred Zuckerman
San Diego, CA, USA
No, this code works great as is.
Sigurd


I believe that I read that in a post from Dev Ashish (one of the gurus of
this group) a long time ago. Namely, that when you open a recordset, it does
not cycle through the records immediately and thus does not have an accurate
RecordCount. But by using MoveLast you insure a complete cycling. I think
it's "possible" to get an accurate RecordCount without a MoveLast, but just
not 100% reliable.
Fred (newbie)

Nov 12 '05 #5
"Fred Zuckerman" <Zu********@sbc global.net> wrote in
news:PA******** ********@newssv r25.news.prodig y.com:
Sigurd & All,
If you open a recordset to check for record count, then don't
you have to include
rs.MoveLast before checking rs.RecordCount?
Fred Zuckerman
San Diego, CA, USA
Fred, if you are checking for the actual number of records, you
need to do a movelast. The recordcount will show 0 if there are no
records or a number >= 1 if there are some records. In this code,
Sigurd is only checking that there is at least ONE record. The
actual value of recordcount is not relevant to the object of the
excercise. It's leveraging known behaviour to get an increase in
speed.

Bob Q.

"Sigurd Bruteig" <s-********@online .no> wrote in message
news:Ul******** ***********@new s4.e.nsc.no...

"Rey" <re********@cox .net> skrev i melding
news:_hWjb.2941 3$gi2.21984@fed 1read01...
> Howdy all.
> Appreciate your help with several problems I'm having:
>


Try this code in subform on current event.

Sigurd
Private Sub Form_Current()
Dim rs As Recordset

Set rs = RecordsetClone
If rs.RecordCount = 0 Then
MsgBox "no records"
Else
MsgBox rs.RecordCount & " records"
End If

End Sub



Nov 12 '05 #6
> If you open a recordset to check for record count, then don't you have to
include
rs.MoveLast before checking rs.RecordCount?


Yes. If you don't, you won't likely get an accurate count.

--
Bruce M. Thompson
bt******@mvps.o rg (See the Access FAQ at http://www.mvps.org/access)
NO Email Please. Keep all communications

within the newsgroups so that all might benefit.<<
Nov 12 '05 #7
> I'm trying to determine if the Visit subform (subformVisits) has a new
record or been changed, i.e. dirty. The form that contains the subform is
named Clients.
If the focus has been moved from the subform to the main form or to another
subform, the subform's record will be saved (no longer "dirty"). If the focus is
currently on that subform, you need only check its dirty property:

If Me.Dirty Then
'Current record has been added or edited
Else
'No edits or no current record
End If
I have this code in the Add Client btn:
If Forms!Clients.s ubformVisits!Vi sitDirty = True Then
MsgBox "Visit subform is dirty!"
Else
MsgBox "problems. subform not dirty"
End If
But it displays err "applicatio n defined or object defined error."
You syntax is incorrect. You must reference the subform *control's* "Form"
property:

Forms!MainFormN ame.SubformCont rolName.Form!Co ntrolName

This assumes that "SubformControl Name" is the name of the subform *control* on
the main form, not the name of the subform (although both may share the same
name).
The field VisitDirty is an unbound & not visible field with a True/False
format in the details section of subformVisits. Its code is:

Private Sub VisitDirty_Afte rUpdate()
' to see if the subform is "dirty", i.e. has changed or new record
If Me.Dirty Then
Me.VisitDirty = True
End If

End Sub
Why would you be trying to set the value of the control after it has been
edited? That's the only time this code would run. Again, you can simply check
the form's "Dirty" property directly ("If Me.Dirty Then ...").
The reason for the unbound VisitDirty field is that I was having a devil of
a time trying to check if the subform was dirty. Probably didn't have the
syntax correct but tried setting a form var below but also had errs. Even
tried going to the control level but no success.

SET frmClient = Forms!Clients.s ubformVISITs
Again, you must reference the subform *control's* "Form" property.
All the above is as the result of a test that caused an err...

The user enters a new record in the Visit subfrom and has tabbed thru the
fields to the DateEntered field into which the current system date is
entered if a new record.

At this point, the DateEntered field is highlighted. If the user - me - then
clicks on the Add Client button instead of the Save button which could/will
happen, I want to save the record in the subform, then move away from the
Dateentered field of the subform to the first name field before calling for
a new record in the Client form using DoCmd.GoToRecor d , , acNewRec

If the cursor is in the DateEntered field when the new record is created
then the current date is entered to the field but an err will soon display
because there is no new client number (autonumber) to insert into the Visit
table clientnum field.
Isn't the "Add Client" command button on the main (Client) form? If so, the
focus will no longer be in the subform, so I guess I don't see where you are
going here unless you are trying to add a child record (in the subform) before
you have created a client record (in the main form).
Guess I need to better understand the Access event model among other things.
Using Access97 and both the client and subformVisit forms are bound to the
Clients and Visits table, respectively.

BTW, what is the difference between using the bang (!) and the dot (.) when
referencing a form as in
Forms!Clients!s ubformVisits and Forms!Clients.s ubformVisit.


From a practical viewpoint, not much, but neither will work unless you are
referencing the subform *control's* "Form" property (I know - nag, nag, nag
<g>).

:-)
--
Bruce M. Thompson
bt******@mvps.o rg (See the Access FAQ at http://www.mvps.org/access)
NO Email Please. Keep all communications

within the newsgroups so that all might benefit.<<
Nov 12 '05 #8
On Fri, 17 Oct 2003 22:22:49 GMT, Bob Quintal <bq******@gener ation.net> wrote:
"Fred Zuckerman" <Zu********@sbc global.net> wrote in
news:PA******* *********@newss vr25.news.prodi gy.com:
Sigurd & All,
If you open a recordset to check for record count, then don't
you have to include
rs.MoveLast before checking rs.RecordCount?
Fred Zuckerman
San Diego, CA, USA


Fred, if you are checking for the actual number of records, you
need to do a movelast. The recordcount will show 0 if there are no
records or a number >= 1 if there are some records. In this code,
Sigurd is only checking that there is at least ONE record. The
actual value of recordcount is not relevant to the object of the
excercise. It's leveraging known behaviour to get an increase in
speed.

Bob Q.

Actually it is relevant becuase of the line -
MsgBox rs.RecordCount & " records"
Without a .MoveLast it can't be guaranteed the MsgBox will return an accurate record count.

You are correct that a RecordCount >=1 indicates that the rs has returned records, but if the RecountCount value is going to be displayed to the user
in any way, the .MoveLast is a must.


"Sigurd Bruteig" <s-********@online .no> wrote in message
news:Ul******** ***********@new s4.e.nsc.no...

"Rey" <re********@cox .net> skrev i melding
news:_hWjb.2941 3$gi2.21984@fed 1read01...
> Howdy all.
> Appreciate your help with several problems I'm having:
>

Try this code in subform on current event.

Sigurd
Private Sub Form_Current()
Dim rs As Recordset

Set rs = RecordsetClone
If rs.RecordCount = 0 Then
MsgBox "no records"
Else
MsgBox rs.RecordCount & " records"
End If

End Sub



Wayne Gillespie
Gosford NSW Australia
Nov 12 '05 #9
Wayne Gillespie <be*****@NObest fitsoftwareSPAM .com.au> wrote in
news:ca******** *************** *********@4ax.c om:

Actually it is relevant becuase of the line -
MsgBox rs.RecordCount & " records"
Without a .MoveLast it can't be guaranteed the MsgBox will
return an accurate record count.

You are correct that a RecordCount >=1 indicates that the rs
has returned records, but if the RecountCount value is going
to be displayed to the user in any way, the .MoveLast is a
must.

You are correct. I read the Original Poster's code, but failed to
note the detail in Sigurd's code, posted as an example.

My error for glossing over little details. However, in real-world
applications, where one needs to know only whether the recordset is
empty, Sigurd's code is adequate. Actually it is better than code
that would have an unnecessary .movelast, being faster.

Bob Q.

Nov 12 '05 #10

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

Similar topics

1
3584
by: Txsg8r | last post by:
I have a main form with a subform on it. When I click a button on the main form, I perform some calculations on data contained in the subform's table (all related records actually). However, after the data is massaged, I refresh it, which takes me to the first record on the subform. Instead, I need to return to the record I had showing on the subform when I clicked the button on the main form. Example: Customer= Main form. Orders =...
3
5291
by: Mark | last post by:
Is this the way to determine if a subform is dirty? If Me!SFrmEnterActivityList.Form.Dirty Then I use this statement in the Unload event of a form. When I click the Close button, the statement is always false whether I have made a change in the subform or not. Thanks!
2
4397
by: Galina | last post by:
Hello I have an application in MS Access 2000. I have a form, which includes a subform. The subform is based on a table, but locked for any editing. There is Edit button. When clicked, it starts a separate unbound form with all the fields, which are on the subform. The fields are filled in with data programmatically. User edits. Edited fields are copied into fields on the subform programmatically as well. I need to catch change in one of...
1
8510
by: John Michael | last post by:
I have a form that has a subform that has a subform. The subform loads a record based on a combo lookup box in the main form. I'm trying to set a value in the subform based on a value in a subform of the subform. the main Form is called Subform is called Subform in the subform is called
4
2965
by: vulcaned | last post by:
Hi All, Hopefully I explain this well........ In Access97 I have a form which has a tab control on it, each tab has a sub-form which is bound to its appropriate table(I'll call them 'Detail' tables). I have a 'Header' table and fields from it are displayed on the form above the tab control. Header table name is tblClientInfo Detail tables are tblPolicyInfo, tblBeneInfo, tblRiderInfo
10
2975
by: Ami | last post by:
Hello everyone, I have developed a small access application and now I need to lock my forms against unwanted edits. I have used the code by Allen Browne I found here http://allenbrowne.com/ser-56.html and it works great, but I need to unlock and lock my main form and subform separately, using two different buttons.
3
1931
by: panwala_bhavesh | last post by:
I have a subform in continuous form style that I use to populate 3 fields (textboxes) on my main form with a double-click of the key-field textbox of the sub: Private Sub TextBattID_DblClick(Cancel As Integer) Forms!. = Me! Forms!. = Me! Forms!. = Me! End Sub
7
4094
by: SBC News Groups | last post by:
I have a form that the user enters some information on and then clicks a button to save the record. I do with the following line: DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70 Once this line executes, I have a sub form that I want to "refresh" because the newly saved information should now display on the sub form. I am trying to do this with this line: Forms!.Requery
1
3235
by: google | last post by:
I have a form with several subforms. Users enter the data, then on the parent there is a command button that runs code to generate a .pdf document from a report based on the data they are working with. If a user enters data in a subform, then directly clicks the command button on the parent form, the data in the subform is not included in their document. I THOUGHT that as soon as focus left the subform, any pending changes to the data...
0
8999
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9394
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9338
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8260
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6803
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6080
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4885
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3322
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2223
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.