473,549 Members | 2,726 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

COMPARE MAIN FORM TEXT BOX ES TO SUBFORM TEXTBOX AND CHANGE BACKCOLOR

Hello,

I have a a form called frmMissyFact, I have copied this form and
called it frmMissyFactBac kup which reads data from a backup database
of the week before. I brought frmMissyFactBac kup into frmMissyFact as
a subform. What I am trying to do is compare each control value from
frmMissyFact to that of frmMissyFactBac kup and if the controlvalue is
different change the backcolor to Yellow of the control so the user
looking at it knows that this field has been changed from last week.
I was able to do this with the following code.

Private Sub Form_Current()

Dim lngYellow As Long

lngYellow = RGB(255, 255, 0)

If Me.STR_PROJECTE D_VOLUME.Value <>
Me.frmMissyFact backup.Form.STR _PROJECTED_VOLU ME.Value Then
Me!STR_PROJECTE D_VOLUME.BackCo lor = lngYellow
Else
End If

If Me.STR_OPEN_DAT E.Value <>
Me.frmMissyFact backup.Form.STR _OPEN_DATE.Valu e Then
Me!STR_OPEN_DAT E.BackColor = lngYellow
Else

End If

End Sub

I would have to do this with every control I have on the form.

The primary key and linked field is Str_Num for the data in both forms
The main problem I have is if when the current database has a new
record (Store Number) and the backup does not. I get an error because
of the code does not see a value in the subform.

Does anybody know how to fix this?
Thanks,
Nov 12 '05 #1
3 4788
You could check whether the Recordset of the subform has a recordcount of 0
at the top of your routine, and exit if it does.

HTH
- Turtle

"pepino13" <pe******@hotma il.com> wrote in message
news:b6******** *************** ***@posting.goo gle.com...
Hello,

I have a a form called frmMissyFact, I have copied this form and
called it frmMissyFactBac kup which reads data from a backup database
of the week before. I brought frmMissyFactBac kup into frmMissyFact as
a subform. What I am trying to do is compare each control value from
frmMissyFact to that of frmMissyFactBac kup and if the controlvalue is
different change the backcolor to Yellow of the control so the user
looking at it knows that this field has been changed from last week.
I was able to do this with the following code.

Private Sub Form_Current()

Dim lngYellow As Long

lngYellow = RGB(255, 255, 0)

If Me.STR_PROJECTE D_VOLUME.Value <>
Me.frmMissyFact backup.Form.STR _PROJECTED_VOLU ME.Value Then
Me!STR_PROJECTE D_VOLUME.BackCo lor = lngYellow
Else
End If

If Me.STR_OPEN_DAT E.Value <>
Me.frmMissyFact backup.Form.STR _OPEN_DATE.Valu e Then
Me!STR_OPEN_DAT E.BackColor = lngYellow
Else

End If

End Sub

I would have to do this with every control I have on the form.

The primary key and linked field is Str_Num for the data in both forms
The main problem I have is if when the current database has a new
record (Store Number) and the backup does not. I get an error because
of the code does not see a value in the subform.

Does anybody know how to fix this?
Thanks,

Nov 12 '05 #2
if both forms have exactly the same control names, use the controls
collection to get the names of the controls on the main form, then
create a variable to point to the "related" control on the subform.
Then just loop through the controls collection.

'-really lame air code, but I hope you get the idea

dim ctl as control
dim frmMain as form
dim frmSub as form

set frm = me
set frmSub = (Can't remember the syntax... see www.mvps.org/access and
there's an article by Keri Hardwick that has the entire listing)...

for each ctl in frm.controls
if ctl.value = frmsub.ctl(ctl. name).value then
'set to normal color
else
ctl.backcolor = vbYellow
end if
end sub

and could ya please not shout?
Nov 12 '05 #3
I am having trouble with the loop. Heres the code

Dim ctl As Control
Dim frmMain As Form
Dim frmSub As Form

Set frmMain = Me
Set frmSub = Me!frmMissyFact backup.Form

For Each ctl In frmMain.Control s
If ctl.Value = frmSub.ctl(ctl. Name).Value Then
'set to normal color
Else
ctl.BackColor = vbYellow
End If
Next ctl
End Sub

I keep getting an error on
If ctl.value = frmSub.ctl(ctl. name).value then
How does it know what controls to compare?
Thanks,


pi********@hotm ail.com (Pieter Linden) wrote in message news:<bf******* *************** ****@posting.go ogle.com>...
if both forms have exactly the same control names, use the controls
collection to get the names of the controls on the main form, then
create a variable to point to the "related" control on the subform.
Then just loop through the controls collection.

'-really lame air code, but I hope you get the idea

dim ctl as control
dim frmMain as form
dim frmSub as form

set frm = me
set frmSub = (Can't remember the syntax... see www.mvps.org/access and
there's an article by Keri Hardwick that has the entire listing)...

for each ctl in frm.controls
if ctl.value = frmsub.ctl(ctl. name).value then
'set to normal color
else
ctl.backcolor = vbYellow
end if
end sub

and could ya please not shout?

Nov 12 '05 #4

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

Similar topics

4
20765
by: codemonkey | last post by:
TIA! I would like to know if there is a way to dynamically change the colors of Subform items? I have already set in place Conditional Formatting so each row has an alernating color scheme, but what I am looking for is a way <behind a button click event> to dynamically change the Subform's color scheme so the listing can have color choices....
1
2241
by: Hasanain F. Esmail | last post by:
Hi All, I am using A2 for this database. I have a main form with bound fields of FlightNumber and FlightDate I also have a subform. This subform takes details of a passanger along with other details. I also have a textbox called status in subform. When a passanger's details are entered, status value is set to "confirmed", when passanger...
17
3838
by: Neil Ginsberg | last post by:
OK, this is a stupid thing, but I can't seem to get this to work. I have a form with a subform (in continuous form view). A combo box on the main form has code in the AfterUpdate event which adds a record to the subform (based on the value of the combo box) and requeries the subform control. I want the focus to return to the combo box on the...
1
1882
by: 2D Rick | last post by:
I have a form that opens maximized and requires scrolling down to see all the textboxes. When you enter a textbox in the lower portion of the form the Enter event opens a large textbox with a large font. This allows the inputter to see from a distance what was just scanned in from the barcoded label on a parcel. When the large textbox closes...
1
3028
by: Henry | last post by:
I was trying to work through the Lab 2 exercises in the Microsoft's Windows-Based Applications in Visual C#. While I am not showing any errors I am also not seeing the mainMenu object when I run the application. I am wondering if someone could point out why in the code below: using System; using System.Drawing; using...
25
4038
by: Neo Geshel | last post by:
This works: <form> <asp:TextBox id="name" /> <%= name.ClientID %> </form> But this DOES NOT work: <form>
4
3135
by: Rod Gill | last post by:
Hi, I have a form that when opened in the designer appears of the screen. The form selector can't be dragged (or resized) and if I scroll right and down to centralise it the form simply jumps further away, completely leaving the selector box area. Any ideas? VS 2003 and VB.Net This is a simple application at the moment but the form is...
0
1192
by: V Arzola | last post by:
I've done extensive work developing a large on-line application form, only to find that it will not render properly in Firefox (1.5.0.1) or Netscape (8.0). The panels are overlapping each other and style settings such as backcolor are not propagating to child elements. Yet, it renders nicely in IE. I've already updated the <browsercaps>...
8
3562
by: Ryan | last post by:
Ok.. I have a form with lots of stuff on it; a tool strip panel, menu strip, data binding elements (dataset, binding source, table adapter), tab control with 7 tab pages, each page contains a picture box, lots of text boxes (for input).. you get the idea. All of a sudden everything on the form has disappeared, it looks like a blank, newly...
0
7451
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
7720
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7475
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...
0
7812
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
6048
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...
0
5089
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
3483
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1061
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
766
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...

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.