Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 4th, 2007, 10:02 PM
Registered User
 
Join Date: Jul 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Combine fields>Runtime error 2450

Hello,

I am attempting a simple routine task but having difficulties for some reason.

I have 2 fields in a form "Daily Diary", which I need to combine to then create the primary key for this corresponding table. (similar to the CustID examples you see everywhere)

In the form after selecting the name from a drop down box, the date is then entered which should then auto populate a "Daily Diary ID" eg Smith07072007. After this the next field to be entered is "Seperable Portion"

When doing this I get " 'Runtime error 2450' can't find the form 'Daily Diary' referred to in a Macro Expression or Code"

My code for the date field in Event - After Update is as follows

Private Sub Date_AfterUpdate()
    Dim fname As String
    Dim lName As String
    Dim cID As String

    lName = Forms!DailyDiary!Date.Text

    Forms!DailyDiary!LastName.SetFocus
    fname = Forms!DailyDiary!LastName.Text

    cID = fname & lName

    Forms!DailyDiary!SeperablePortion.SetFocus

End Sub.

Any help would be great.
P.s. my access knowledge is rather basic.

Cheers

Chris
Reply With Quote
  #2 (permalink)  
Old July 5th, 2007, 03:29 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Hampshire, United Kingdom.
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Chris,

Is the form opened/loaded at the time?
I believe the Forms collection only returns forms that are currently open...

If you are actually working in this form, then you can scrap the qualifiers (Forms!DailyDiary)..

e.g SerperablePortion.SetFocus

A good thing to get used to in Access VBA is the Ctrl+J keys, this will bring up your intellisense
which will allow you to see what objects/values you have access to..
If SeperablePortion does not appear in your intellisense, then something strange is going on!

And of course, always check for typos, we've all been had by them..

If your still having probs after checking all this, please let us know..

Regards,
Rob

Reply With Quote
  #3 (permalink)  
Old July 5th, 2007, 06:29 PM
Registered User
 
Join Date: Jul 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Rob,

That Ctrl+J trick is brilliant. I went through all the code and selected everything from the accessible objects so the code looks as follows.

Private Sub Date_AfterUpdate()
    Dim fname As String
    Dim lName As String
    Dim cID As String

    lName = [Form_Daily Diary]!Date.Text

    [Form_Daily Diary]!LastName.SetFocus
    fname = [Form_Daily Diary]!LastName.Text

    cID = fname & lName
[Form_Daily Diary]![Seperable Portion].SetFocus

However I now get an error runtime error 438 - object does not support this property or method....which is relating to the last setfocus line. In the locals window the concatenate seems to work just doesn't want to move on afterwards.

Thanks again.

Chris
Reply With Quote
  #4 (permalink)  
Old July 6th, 2007, 02:44 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Hampshire, United Kingdom.
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

Chris,

Use can TextBox.Value rather than TextBox.Text, then you wont need to set the focus to it...

Give that a whirl and see if it does the trick...

The only reason I could thing that this would not work is that the TextBox is not actually a TextBox (label perhaps?) or the TextBox has been set to Locked in the Form Designer..

Regards,
Rob

Reply With Quote
  #5 (permalink)  
Old July 6th, 2007, 07:10 AM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

If you are always working in Form_Daily Diary, then you can replace Forms.[Form_Daily Diary].Form with simply Me. Also, don't name the textbox DATE because that's a built-in Access function that gives you today's date. I'll use MyDate instead.

cID = Me.LastName & Format(Me.MyDate, "mmddyyyy")

Or if you really DO want today's date

cID = Me.LastName & Format(Date(), "mmddyyyy")


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
runtime error 2450 gotcha123 Access VBA 0 August 25th, 2008 02:59 PM
run-time error '2450' kk_sg Access VBA 2 August 21st, 2006 10:26 AM
Run-time error '2450' bmurrin Access VBA 6 May 31st, 2006 07:11 AM
Can't find subform referred to in VBA Error 2450 mmcdonal Access VBA 2 April 18th, 2005 10:05 AM



All times are GMT -4. The time now is 11:59 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.