Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old September 16th, 2003, 12:06 PM
Friend of Wrox
 
Join Date: Sep 2003
Location: Madison, Wisconsin, USA.
Posts: 451
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Ben Horne
Default Problems With New VBA Code

Hi,

I tried implementing a new piece of VBA code inside my Media Information Multi-page form. What it's supposed to do is this: After the DownloadLocation field is updated with a new field value, that field value is supposed to be displayed in a certain color NEXT to the DownloadLocation textbox. Thing is, I cannot get the result to display in the correct location AND the Spelling Checker pops up at times when I don't want it to.:( If you need the VBA code, I will be glad to post it here:)

Thanks

Ben
__________________
Ben Horne
-------------------------
I don\'t want to sound like I haven\'t made any mistakes. I\'m confident I have.

Most likely using FireFox and concocting my next Macromedia Flash project
Snibworks Forums Moderator

Welcome to the New Age
  #2 (permalink)  
Old September 17th, 2003, 02:25 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Melbourne, Vic, Australia.
Posts: 308
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey Ben,

What I'm assuming is this -

You've got a label next to the textbox, and have some code in the AfterUpdate event of DownloadLocation as something like this:

Code:
Private Sub DownloadLocation_AfterUpdate()
If DownloadLocation="Criterion" Then
Me.SomeLabel.ForeColor = vbRed
Else
Me.SomeLabel.ForeColor = vbBlack
End if

Me.SomeLabel.Caption=DownloadLocation

End Sub
If that's the case, and it's still not working, post your code,
If that is NOT the case, post your code.
Basically - post the code ^_^

Steven

I am a loud man with a very large hat. This means I am in charge
  #3 (permalink)  
Old September 17th, 2003, 02:51 PM
Friend of Wrox
 
Join Date: Sep 2003
Location: Madison, Wisconsin, USA.
Posts: 451
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Ben Horne
Default

Hi Steven,

I forgot to add - I'm going by my New Perspectives On Microsoft Access 2002 textbook that I bought from the MATC Truax Bookstore for my Access courses. Basically, all the code that I have written up to this point has worked as I expected. The code that I need to write is in the Access 2002 textbook BUT It does not look like the example code you talked about. I'll post the code here anyways

Quote:
quote:Originally posted by Steven
 Hey Ben,

What I'm assuming is this -

You've got a label next to the textbox, and have some code in the AfterUpdate event of DownloadLocation as something like this:

Code:
Private Sub DownloadLocation_AfterUpdate()
If DownloadLocation="Criterion" Then
Me.SomeLabel.ForeColor = vbRed
Else
Me.SomeLabel.ForeColor = vbBlack
End if

Me.SomeLabel.Caption=DownloadLocation

End Sub
If that's the case, and it's still not working, post your code,
If that is NOT the case, post your code.
Basically - post the code ^_^

Steven

I am a loud man with a very large hat. This means I am in charge
Ben
  #4 (permalink)  
Old September 19th, 2003, 04:31 PM
Friend of Wrox
 
Join Date: Sep 2003
Location: Madison, Wisconsin, USA.
Posts: 451
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Ben Horne
Default

Steven,

I'm working from my New Perspectives On Microsoft Access 2002 textbook that is published by Course Technology

I originally had the code as shown below

Private Sub Form_Current()
    [DownloadLocation].Visible = True
    Select Case [DownloadLocation]
        Case "Kazaa Media Network"
            [DownloadLocation] = "Kazaa Media Network"
            [DownloadLocation].Forecolor = RGB (255, 0, 0)
        Case "GarageBand Records"
            [DownloadLocation] = GarageBand Records"
            [DownloadLocation].Forecolor = RGB (255, 45, 0)

Do you see anything wrong with this code If so, I'm open to suggestions as to how I can change it.:)

Thanks,

Quote:
quote:Originally posted by Steven
 Hey Ben,

What I'm assuming is this -

You've got a label next to the textbox, and have some code in the AfterUpdate event of DownloadLocation as something like this:

Code:
Private Sub DownloadLocation_AfterUpdate()
If DownloadLocation="Criterion" Then
Me.SomeLabel.ForeColor = vbRed
Else
Me.SomeLabel.ForeColor = vbBlack
End if

Me.SomeLabel.Caption=DownloadLocation

End Sub
If that's the case, and it's still not working, post your code,
If that is NOT the case, post your code.
Basically - post the code ^_^

Steven

I am a loud man with a very large hat. This means I am in charge
Ben
  #5 (permalink)  
Old September 22nd, 2003, 07:19 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Melbourne, Vic, Australia.
Posts: 308
Thanks: 0
Thanked 0 Times in 0 Posts
Default

OK - here's the reasoning behind the code that I had written:

Quote:
quote:After the DownloadLocation field is updated with a new field value
Therefore, you need something attached to the After Update event.
You've got it on Form_Current - which means it only changes when you change records

In your Case statement, you're technically changing the value of [DownloadLocation], but you're just changing it to what it already is, so the bit where you have [DownloadLocation] = "Kazaa Media Network", is totally redundant, because in order to change it to that, it has to be that already (eg: "if Field=A then Field=A" is completely pointless)

You also said that you wanted the text displayed NEXT to the field - in other words - not in the field itself, so I assumed you'd put it in a label.

So as a summary - this is what my code does:
When the field is updated, the value of the field is displayed next to it, in a colour which is based on the value of the field

and what your code does is:
When the current record changes, the new value of the text box is changed to be the same as what it already is, and the text is changed based on the value of the field.

A combination of the two codes (which is basically just my original one written as a Case statement rather than an If statement):

Code:
Private Sub DownloadLocation_AfterUpdate()

Select Case DownloadLocation

    Case "Kazaa Media Network"
        SomeLabel.Forecolor = vbRed
    Case "GarageBandRecords"
        SomeLabel.Forecolor = RGB (255, 45, 0)
    Case Else
        SomeLabel.Forcolor = vbWhite

End Select

SomeLabel.Caption = DownloadLocation

End Sub

While both codes will actually function, it's what they actually do that differs.

So, other than making the value of the field "change" unnecessarily, your code works fine. But the thing is - what exactly is it you want to do?

Do you want the colour of the text in the textbox to change?
or do you want the color of the text in something else to change?
Do you want this to fire when the record changes?
or do you want it to fire when the value of the textbox changes?

It's because of different answers to these questions that our code differs so much.

Steven

I am a loud man with a very large hat. This means I am in charge


Similar Threads
Thread Thread Starter Forum Replies Last Post
Code works in Excel VBA but not Access VBA fossx Access VBA 2 May 21st, 2007 08:00 AM
VBA Query Problems LiamBFC Access VBA 2 April 11th, 2006 06:26 AM
Excel 2000 VBA Problems drsammyb Excel VBA 0 January 17th, 2005 11:41 AM
Problems introducing a formula using VBA mariona_cid Excel VBA 0 June 1st, 2004 07:01 PM
Saving Excel VBA code gives problems - Help needed mjaitly Excel VBA 0 April 14th, 2004 07:23 AM





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