473,573 Members | 5,078 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 24791

"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
3570
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...
3
5278
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
4374
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...
1
8443
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
2953
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...
10
2962
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
1923
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
4083
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....
1
3229
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...
0
7709
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8218
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...
0
8091
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6435
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...
1
5605
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...
0
5296
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...
0
3738
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2228
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
1
1330
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.