473,397 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

ms access command button

553 512MB
Hi
I am new in Ms Access

I need to know how can i create a command button on a form. When it is clicked, a table is opened that is associated to the data in a field i have.

E.g: if ( surName == "abc") then open table Table_Abc
if ( surName == "qaz") then open table Table_Qaz

i will have a lot of surnames, so tables needs to be opened accordingly.

Will it be done by macro, or expressin builder? If it needs VB code, can you give me that as i dont know VB

thank you very much

hassan
Feb 14 '07 #1
24 5314
Rabbit
12,516 Expert Mod 8TB
Do you need a seperate table for each surname? It may be easier to create a query that filters for the surname and then open the query. To open a query you use the code:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenQuery "Name of Query"
Feb 14 '07 #2
questionit
553 512MB
Do you need a seperate table for each surname? It may be easier to create a query that filters for the surname and then open the query. To open a query you use the code:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenQuery "Name of Query"
yes i need seperate tables.. how can i do it then?
Feb 14 '07 #3
Rabbit
12,516 Expert Mod 8TB
yes i need seperate tables.. how can i do it then?
Why do you need seperate tables?

The code to open a table for your naming convention would be:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenTable "Table_" & Surname
Feb 14 '07 #4
questionit
553 512MB
Why do you need seperate tables?

The code to open a table for your naming convention would be:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenTable "Table_" & Surname
What will keyword Table_ do?

will i have to re-write this line of code for every surname?

i have different tables that contains details (more than 5 rows) of every surname.
is there any better way doing it than having seperate tables?

thanks a lot
Feb 14 '07 #5
Rabbit
12,516 Expert Mod 8TB
What will keyword Table_ do?

will i have to re-write this line of code for every surname?

i have different tables that contains details (more than 5 rows) of every surname.
is there any better way doing it than having seperate tables?

thanks a lot
"Table_" is not a keyword. I assumed you used the format Table_Surname to name all your tables. "Table_" & Me.Surname.Value will return the string Table_Surname assuming that Surname is a control on your form.

What details of the surname are you storing? One way to keep all the data centralized is to have a field that designates which surname the record belongs to.

Take a look at Normalisation and Table Structures, it will help you structure your tables.
Feb 14 '07 #6
questionit
553 512MB
"Table_" is not a keyword. I assumed you used the format Table_Surname to name all your tables. "Table_" & Me.Surname.Value will return the string Table_Surname assuming that Surname is a control on your form.

What details of the surname are you storing? One way to keep all the data centralized is to have a field that designates which surname the record belongs to.

Take a look at Normalisation and Table Structures, it will help you structure your tables.
thanks i am getting undertanding now.
What is Me keyword? will it be the name of the form? I have written this code and getting an error: "method or data member not found". ?

DoCmd.OpenTable "Table_" & Me.surName_Label.Value
Feb 14 '07 #7
questionit
553 512MB
thanks i am getting undertanding now.
What is Me keyword? will it be the name of the form? I have written this code and getting an error: "method or data member not found". ?

DoCmd.OpenTable "Table_" & Me.surName_Label.Value
I thought that surname_Label was wrong. this now code. Also i changed Me to Form (the name of the form)?

DoCmd.OpenTable "Table_" & Form.surName.Value

but now when i run i get error: .. cant find object Table_surName1.

surName1 is a table i have created. why it cant find it?
Feb 14 '07 #8
MMcCarthy
14,534 Expert Mod 8TB
thanks i am getting undertanding now.
What is Me keyword? will it be the name of the form? I have written this code and getting an error: "method or data member not found". ?

DoCmd.OpenTable "Table_" & Me.surName_Label.Value
1. The Me. refers to the current form.
2. You cannot use .Value on a label, thy the following

Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenTable "Table_" & Me.surName_Label.Caption
Mary
Feb 14 '07 #9
questionit
553 512MB
1. The Me. refers to the current form.
2. You cannot use .Value on a label, thy the following

Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenTable "Table_" & Me.surName_Label.Caption
Mary
But i have tried this:

DoCmd.OpenTable "Table_" & Detail.surName.Value

surName is Text Box
Detail is the Detail portion where the surName TextBox is - under the Header

I get following error now: Method or Data Value not found?
Please help.
Feb 15 '07 #10
MMcCarthy
14,534 Expert Mod 8TB
But i have tried this:

DoCmd.OpenTable "Table_" & Detail.surName.Value

surName is Text Box
Detail is the Detail portion where the surName TextBox is - under the Header

I get following error now: Method or Data Value not found?
Please help.
Try ...

Expand|Select|Wrap|Line Numbers
  1.  DoCmd.OpenTable "Table_" & Me.surName
Feb 15 '07 #11
questionit
553 512MB
Try ...

Expand|Select|Wrap|Line Numbers
  1.  DoCmd.OpenTable "Table_" & Me.surName
now i get a different error:

'.. cant find the object Table_detail1'

i have a surname value 'detail1' and have also a table called 'detail1', so there should be any error generated ?
Feb 15 '07 #12
MMcCarthy
14,534 Expert Mod 8TB
now i get a different error:

'.. cant find the object Table_detail1'

i have a surname value 'detail1' and have also a table called 'detail1', so there should be any error generated ?
If the table is called 'detail1', you don't need the 'Table_' part, just ...

Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenTable Me.surName
Feb 15 '07 #13
questionit
553 512MB
If the table is called 'detail1', you don't need the 'Table_' part, just ...

Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenTable Me.surName
That worked. thanks

by the way. would you tell me why was i actually told to use 'Table_' .. when do we need this?
Feb 15 '07 #14
MMcCarthy
14,534 Expert Mod 8TB
That worked. thanks

by the way. would you tell me why was i actually told to use 'Table_' .. when do we need this?
Rabbit was talking about naming conventions. By convention tables are named Table_Name or tblName.

Mary
Feb 15 '07 #15
questionit
553 512MB
Rabbit was talking about naming conventions. By convention tables are named Table_Name or tblName.

Mary
Ok
Now if i want to open detail1 table in a form.. I know i need to create a form first.

But there are many tables e.g detail1, detail2, etc ... but all have exactly similar fields.

How will i set it..... open a form that will actually be opening appropriate table i.e detail1, detail2, etc ?
Feb 15 '07 #16
MMcCarthy
14,534 Expert Mod 8TB
Ok
Now if i want to open detail1 table in a form.. I know i need to create a form first.

But there are many tables e.g detail1, detail2, etc ... but all have exactly similar fields.

How will i set it..... open a form that will actually be opening appropriate table i.e detail1, detail2, etc ?
You need to change the record source of the form each time. In the forms On load event put the following code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.  
  3.   ' Replace FormName with the name of the Form with the surName textbox.
  4.   Me.RecordSource = Forms![FormName]![surName]
  5.  
  6. End Sub
Mary
Feb 15 '07 #17
questionit
553 512MB
You need to change the record source of the form each time. In the forms On load event put the following code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.  
  3.   ' Replace FormName with the name of the Form with the surName textbox.
  4.   Me.RecordSource = Forms![FormName]![surName]
  5.  
  6. End Sub
Mary
I cant find the ' On Load' event. it is not in the form properties box ?
Feb 15 '07 #18
MMcCarthy
14,534 Expert Mod 8TB
I cant find the ' On Load' event. it is not in the form properties box ?
It should be under the event tab. Scroll down. It's definitely there.

Mary
Feb 15 '07 #19
questionit
553 512MB
It should be under the event tab. Scroll down. It's definitely there.

Mary
OnLoad event would be in the properties of the form, not of the button, right?
And It is not there under the Even Tab..

how can i attach an image with this message? the attach an image button prompts me and asks to enter text to be formatted- what is that

i dont know if i am gonig totally wrong. but under the event tab ,on load is not present?
Feb 16 '07 #20
MMcCarthy
14,534 Expert Mod 8TB
OnLoad event would be in the properties of the form, not of the button, right?
And It is not there under the Even Tab..

how can i attach an image with this message? the attach an image button prompts me and asks to enter text to be formatted- what is that

i dont know if i am gonig totally wrong. but under the event tab ,on load is not present?
Are you sure you are in the forms properties. Does it say Form in the Blue Bar at the top of the properties box?

Mary
Feb 18 '07 #21
questionit
553 512MB
Are you sure you are in the forms properties. Does it say Form in the Blue Bar at the top of the properties box?

Mary
. My form is called 'names'.. so it says on the Blue bar: 'names: Form' . And the properties box says ' Section: Detail' - this text 'Secion: Detail' remains same no matter what the form is called.

Is there any way i can go directly into the code input area and type in the required code?
Feb 18 '07 #22
questionit
553 512MB
. My form is called 'names'.. so it says on the Blue bar: 'names: Form' . And the properties box says ' Section: Detail' - this text 'Secion: Detail' remains same no matter what the form is called.

Is there any way i can go directly into the code input area and type in the required code?
I am sorry, i have found OnLoad now. It was under 'Form'.. i was looking under the 'Detail'.

But with On Load code , there comes another confusion.

Previously, you had given me a code so that when the button is pressed, an appropriate table is opened (the same as the surName).. it worked fine!

But the On Load code, i have now put in the form's(called 'details') On Load property. This form need to be opened when the command button is pressed (on the main form).

But the table the 'details' form will use to get data will be different all the times (different with different surname!) ... so where would i put the OnLoad code?

i have tried putting onLoad code in the 'details' form's OnLoad property, but nothings happens... When i press the button, appropriate tables are opened -not the 'details' form ??


Thanks
Feb 18 '07 #23
questionit
553 512MB
I am sorry, i have found OnLoad now. It was under 'Form'.. i was looking under the 'Detail'.

But with On Load code , there comes another confusion.

Previously, you had given me a code so that when the button is pressed, an appropriate table is opened (the same as the surName).. it worked fine!

But the On Load code, i have now put in the form's(called 'details') On Load property. This form need to be opened when the command button is pressed (on the main form).

But the table the 'details' form will use to get data will be different all the times (different with different surname!) ... so where would i put the OnLoad code?

i have tried putting onLoad code in the 'details' form's OnLoad property, but nothings happens... When i press the button, appropriate tables are opened -not the 'details' form ??


Thanks
Mary..i have done it . it is working..

i put this code for the command button:

DoCmd.OpenForm "details"

and in the 'details' form onLoad properties, i put the code you have provided me

Thanks a lot..
Feb 18 '07 #24
MMcCarthy
14,534 Expert Mod 8TB
I am sorry, i have found OnLoad now. It was under 'Form'.. i was looking under the 'Detail'.

But with On Load code , there comes another confusion.

Previously, you had given me a code so that when the button is pressed, an appropriate table is opened (the same as the surName).. it worked fine!

But the On Load code, i have now put in the form's(called 'details') On Load property. This form need to be opened when the command button is pressed (on the main form).

But the table the 'details' form will use to get data will be different all the times (different with different surname!) ... so where would i put the OnLoad code?

i have tried putting onLoad code in the 'details' form's OnLoad property, but nothings happens... When i press the button, appropriate tables are opened -not the 'details' form ??


Thanks
You need two pieces of code.

One for the command button to open the details form and the second one for the On Load event of the details form to change the record source to the table chosen in the previous form.

Make sure the Details form is set to Form view and not datasheet view.

Mary
Feb 18 '07 #25

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Nathan Bloom | last post by:
Is there a way to force the user of a database to exit and close access through a close button on for example a switchboard menu? If a user closes access by the exit command or the close button...
8
by: Colleyville Alan | last post by:
I have been working on an Access app that takes info from a file and writes it to a spreadsheet on a form, simultaneously saving the spreadsheet to Excel. I got the idea that the same concept...
49
by: Yannick Turgeon | last post by:
Hello, We are in the process of examining our current main application. We have to do some major changes and, in the process, are questionning/validating the use of MS Access as front-end. The...
8
by: Ron B | last post by:
Help!!! What am I doing wrong? I am working with Office 2003 and am trying to create a command button on an Access form that will create a mail merge in Word from an Access table. I want to...
24
Dököll
by: Dököll | last post by:
Jumped for joy last night after learning, indeed, the command button wizard can be switched on or off. Well this occured here, with my Access 2000...an attempt to redo at work failed. Here's the...
1
by: CoolFactor | last post by:
MY CODE IS NEAR THE BOTTOM I want to export this Access query into Excel using a command button on an Access form in the following way I describe below. Below you will find the simple query I am...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
4
by: zufie | last post by:
I have a main form containing a command SEND button that prompts an email form to pop up. The email address(es) that are supposed to appear on the email form are those corresponding to the...
0
by: Tony | last post by:
I am continuing to develop an Access 2007 application which was originally converted from Access 2003. In Access 2003 I was able to disable the Access Close button in the top righthand corner of...
5
by: Tony | last post by:
I am continuing to develop an Access 2007 application which was originally converted from Access 2003. In Access 2003 I was able to disable the Access Close button in the top righthand corner of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.