Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Software Development
Tag Cloud
access acer asus bios bsod computer crash desktop driver drivers error ethernet excel freeze gaming hard drive hardware hdmi internet laptop malware memory monitor motherboard network operating system printer problem ram registry router slow software sound svchost.exe toshiba trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Software & Hardware > Software Development >
Solved: MS Access: Automatically determine the value of one field from an ID autonumb

Reply  
Thread Tools
maxx_eclipse's Avatar
Computer Specs
Member with 286 posts.
 
Join Date: May 2007
Location: http://127.0.0.1
Experience: Intermediate In Few Areas
16-Jan-2010, 02:42 AM #1
Solved: MS Access: Automatically determine the value of one field from an ID autonumb
Afternoon all,

Let me explain what I am attempting to do here:

I have a database with a list of contacts, and with these list of contacts, I have also created an agenda. Inside this agenda table, I have a field called "Contact ID". "Contact ID" has a one-to-many relationship set up with the primary key in the contacts table, "ID". (refer to pic1.jpg) I intend for the database to automatically update the "Contact ID" based on what contact is currently selected.

For example, If I open a contact with ID #3 (refer to pic2.jpg), and then I open the Agenda form, the "Contact ID" will automatically update to the contact "ID". From here, I can add events and such that will automatically relate to that particular client.

My problem is I don't know how I should do this, whether I need to set a default value for "Contact ID", use a query, or use some sort of VB coding to get it done. I've already tried to use things like:

Code:
Private Form_Load()

[AGENDA].[Contact ID] = [CONTACTS].[ID]
and that didn't work. I assume I might need something like a TempVar or ActiveForm/ActiveDatasheet code to call for ID to be automatically updated?

Thanks for your help everyone, looking forward to your responses!
Attached Thumbnails
Solved: MS Access: Automatically determine the value of one field from an ID autonumb-pic1.jpg   Solved: MS Access: Automatically determine the value of one field from an ID autonumb-pic2.jpg  

Last edited by maxx_eclipse; 16-Jan-2010 at 03:00 AM..
maxx_eclipse's Avatar
Computer Specs
Member with 286 posts.
 
Join Date: May 2007
Location: http://127.0.0.1
Experience: Intermediate In Few Areas
19-Jan-2010, 04:27 AM #2
I've gotten this far with some results:

Code:
Private Sub Form_Load()
On Error Resume Next
    
Dim ID2CID As Integer
    
    Application.SetOption "Confirm Action Queries", False
    ID2CID = Screen.ActiveControl
    MsgBox ID2CID
    
End Sub
The MsgBox displays the required ID, but now I'm having trouble telling the program that when the Agenda form is open, Variable "ID2CID" is set as [ContactID].

I tried to do the following:

Code:
Private Sub Agenda_Click()

    [ContactID] = ID2CID

End Sub
but nothing happens. But when I try:

Code:
Private Sub SUBFORM_AGENDA_Enter()

    [ContactID] = ID2CID

End Sub
I get the following error:

Quote:
Run-time error '2465':

Address Book* (* my database name) can't find field 'l' referred to in your expression.
I fail to understand where VB is picking up the letter 'l' in my expression, because out of all letters of the alphabet, there is not a single letter 'l' in there. I confirmed this by checking Notepad with the character input, and it does say that the error is with the letter 'l'. Not capital 'i' or the number '1'...

Microsoft VB help gives me the associated help ID HV01202015, which says:

Quote:
Keyword Not Found

The keyword you selected can't be found in Visual Basic Help. You may have misspelled the keyword, selected too much or too little text, or asked for help on a word that isn't a valid Visual Basic keyword.

The keyword you want help on may be contained within an object library that is not referenced. Make sure references are set to the appropriate object libraries for all objects used in your code.

The easiest way to get help on a specific keyword is to position the insertion point anywhere within the keyword and press F1. You don't have to select the keyword. In fact, if you select only a portion of the keyword, or more than a single word, Help won't find what you're looking for.

The Value property topic is displayed when you press F1 with the insertion point between the "a" and the "l" in the Value keyword as shown in the following example.

Code:
Worksheets(1).Range ("A2").value=3.14159


Any ideas on how I can set [ContactID] as "ID2CID"?

Last edited by maxx_eclipse; 19-Jan-2010 at 04:33 AM..
maxx_eclipse's Avatar
Computer Specs
Member with 286 posts.
 
Join Date: May 2007
Location: http://127.0.0.1
Experience: Intermediate In Few Areas
19-Jan-2010, 04:51 AM #3
Well, I've tried something new:

Code:
Private Sub Form_Load()

Dim ID2CID As Integer
    
    Application.SetOption "Confirm Action Queries", False
    ID2CID = Screen.ActiveControl
    Forms!SUBFORM_AGENDA.Controls!ContactID = ID2CID
    
End Sub
And I now get:

Quote:
Run-time error '2450':

Address Book can't find the form 'SUBFORM_AGENDA' referred to in a macro expression or Visual Basic code.
It seems that VB can't set the property (or value, in this case) of a field because the form is actually not open. When I opened the form in the background, there was actually no problem in setting the value.

I will continue to post my developments and issues here for those who are interested in following, as trivial (or complicated) as this might be to some.

Last edited by maxx_eclipse; 19-Jan-2010 at 05:02 AM..
OBP's Avatar
OBP OBP is offline
Computer Specs
Distinguished Member with 14,665 posts.
 
Join Date: Mar 2005
Location: UK
Experience: An old Basic Programmer
19-Jan-2010, 03:37 PM #4
You are going about this completely the wrong way around and making it very difficult.
It is normal to have the Agenda table data as a Subform on a Mainform that has the Contact ID on it.
The 2 forms are Linked via Master/Child links so that any new record in the Subform is automatically generated with the Correct Contact ID and only those Records with that contact id will be displayed for that Contact.
If you insist on opening a separate form for the Agenda data's new Record you pass the Contact ID using the The OpenArgs function and VBA. Or use Vba to reference the opening Contact Form before it is closed (if you are closing it).
__________________
OBP
I do not give up easily
maxx_eclipse's Avatar
Computer Specs
Member with 286 posts.
 
Join Date: May 2007
Location: http://127.0.0.1
Experience: Intermediate In Few Areas
20-Jan-2010, 04:44 AM #5
...I honestly have no idea what's going on now.

My two problems I'm having now is this:

1) I can't get Access to automatically link the ID of the customer to the agenda "Contact ID" field, so that any new appointments/interactions/events related to a particular customer will have his/her ID copied to the agenda field. Everytime I add something, I have to manually input the contact ID, I can't get a relationship established to do it automatically.

2) I'm having general issues with the Agenda now. In my agenda form, I have the master form, which is the detailed form view, displaying the text boxes of all the fields, within the master form, I have a subform, which is supposed to be the datasheet view, so that when I select an entry in the datasheet (subform), the master form is updated to display the selected entry. I tried using the VB provided here on the MSDN help page (http://msdn.microsoft.com/en-us/libr...offtips_topic7), but VBA responds with "expected: expression".

I've been searching the internet for a solution to this problem, and it's been quite an irksome situation. Anyone know what I need to do?

Last edited by maxx_eclipse; 20-Jan-2010 at 04:50 AM..
maxx_eclipse's Avatar
Computer Specs
Member with 286 posts.
 
Join Date: May 2007
Location: http://127.0.0.1
Experience: Intermediate In Few Areas
20-Jan-2010, 04:55 AM #6
Well, part of the problem is solved:

In my state of confusion and frustration, I really didn't understand what your point was. I took a break, and when I came back, I had gone and editted the "Master Link Field" and "Child Link Field", to 'ID' and 'ContactID' respectively. And now it all falls into place!

Thanks OBP for "knocking" some sense in to me. Now I can move on!

But I'm still having one minor issue, when I select a record in the datasheet (subform), there is no dynamic update to display the same record in the master form. I suppose I need to have some "On Current" or "On Change" code to fix this? I suppose I could use a DoCmd.GoToRecord and a string to tell it which record to update to?

Last edited by maxx_eclipse; 20-Jan-2010 at 05:35 AM..
OBP's Avatar
OBP OBP is offline
Computer Specs
Distinguished Member with 14,665 posts.
 
Join Date: Mar 2005
Location: UK
Experience: An old Basic Programmer
20-Jan-2010, 07:16 AM #7
I posted a VBA example of what you want to do some time ago, I will see if I can find it.
OBP's Avatar
OBP OBP is offline
Computer Specs
Distinguished Member with 14,665 posts.
 
Join Date: Mar 2005
Location: UK
Experience: An old Basic Programmer
20-Jan-2010, 07:19 AM #8
maxx_eclipse's Avatar
Computer Specs
Member with 286 posts.
 
Join Date: May 2007
Location: http://127.0.0.1
Experience: Intermediate In Few Areas
21-Jan-2010, 02:00 AM #9
OBP, I had a look at the VBA, but I'm receiving the following error:

Run-time error code '3159':

Not a valid bookmark.

Any ideas what this means?

I'm told that the error originates here:

Code:
Me.Parent.Bookmark = Me.Bookmark
OBP's Avatar
OBP OBP is offline
Computer Specs
Distinguished Member with 14,665 posts.
 
Join Date: Mar 2005
Location: UK
Experience: An old Basic Programmer
21-Jan-2010, 01:11 PM #10
Sorry, I forgot to say that the Version that I posted does not use a split Form, it uses an actual Subform that works like a Split Form. That is required to overcome the problem with the Split Form.
You als need all of the Code in all of the sections in both Forms.
__________________
OBP
I do not give up easily
maxx_eclipse's Avatar
Computer Specs
Member with 286 posts.
 
Join Date: May 2007
Location: http://127.0.0.1
Experience: Intermediate In Few Areas
22-Jan-2010, 12:53 AM #11
I added all the code in all of the sections in both forms, but I still get the same error.
OBP's Avatar
OBP OBP is offline
Computer Specs
Distinguished Member with 14,665 posts.
 
Join Date: Mar 2005
Location: UK
Experience: An old Basic Programmer
22-Jan-2010, 08:06 AM #12
Did you create a separate Subform?
Does the database that I posted work when you open it?
maxx_eclipse's Avatar
Computer Specs
Member with 286 posts.
 
Join Date: May 2007
Location: http://127.0.0.1
Experience: Intermediate In Few Areas
23-Jan-2010, 08:54 AM #13
Now that you mention it, when I opened it, no data was displayed on any of the forms that I opened...

Could I be missing some VBA object?

Here's my latest list:

Quote:
Visual Basic for Applications
Microsoft Access 12.0 Object Library
OLE Automation
Microsoft ActiveX Data Objects 2.1 Library (*)
Microsoft JET & Replication Objects 2.6 Library
Microsoft Office 12.0 Object Library
Microsoft Office 12.0 Access Database Engine Object Library (ACEDAO)
Microsoft Visual Studio 2008 Tools for Office Execution engine 9.0 Object Library
(*) I have version 6.0 of the ActiveX Data Objects Library, does it really matter which one I have referenced?

Last edited by maxx_eclipse; 23-Jan-2010 at 09:16 AM..
OBP's Avatar
OBP OBP is offline
Computer Specs
Distinguished Member with 14,665 posts.
 
Join Date: Mar 2005
Location: UK
Experience: An old Basic Programmer
23-Jan-2010, 02:18 PM #14
The data is not being displayed because of the Date Filter in the Query, it is set to >Date()-30 And <Date()+30, set it to >Date()-150 And <Date()+30 to see the data or remove the filter altogether.
maxx_eclipse's Avatar
Computer Specs
Member with 286 posts.
 
Join Date: May 2007
Location: http://127.0.0.1
Experience: Intermediate In Few Areas
24-Jan-2010, 11:55 PM #15
Okay, I made the change, and the data now shows up, but I noticed that the only way to have the information update is to click on the row selector (black-right arrow), and even then, when I select the data, the subform reformats itself, and half the normal view is cut off and the datasheet is "moved up".

Does this happen on your side?
Reply

Tags
access, autonumber, id number, relationship, subform

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 12:15 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.