Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
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
 
Old July 4th, 2007, 10:02 PM
Registered User
 
Join Date: Jul 2007
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
 
Old July 5th, 2007, 03:29 AM
Friend of Wrox
 
Join Date: Mar 2007
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

 
Old July 5th, 2007, 06:29 PM
Registered User
 
Join Date: Jul 2007
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
 
Old July 6th, 2007, 02:44 AM
Friend of Wrox
 
Join Date: Mar 2007
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

 
Old July 6th, 2007, 07:10 AM
Friend of Wrox
 
Join Date: Jun 2003
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





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





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