Vba to make the textbox show record value

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
Hi, i want to know how to make Vba show record value in textbox1 in myform1.

when the form load, if the environ username is pedie1 then i want "pedie1" table's record1 of field1 show in textbox1.

Please please help me out.

Thanks in advance.
 
Pedie

Why are you insisting on using code when you shouldn't need to?

Mind you if you have a separate table for each person you might need code, but you shouldn't have a separate table for each person in the first place.

That's just the wrong way to set things up and not a very good start if you are trying to learn how to use Access.

Do you have separate tables for each person?

If you do, do those tables have the same fields?
 
Upvote 0

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Question: What is the rationale for having different users employ different tables off the same form? Are you able to give a real life example of what you are attempting to do here? This concept is new to me and I cannot envision it.

Alan
 
Upvote 0
Thanks again and this is realtime. I didnt want to bother with long question so i thought i'd ask small question and take care the rest myself... :)

I have different table for different users [who are managers] when they log on this this access form i want the texboxes that are in form show the emps directly reporting to them...which will be around 5-7, from thier respective table.
I know it might not make lot of sense but i think this is the best way...:)

Thanks again Norie, and everyone!
Xen, 'm still not able to make the code work....:)
 
Upvote 0
Pedie

Please forget about code - you don't need it.

You could do the whole thing with one table but it would make more sense to have at least 2 because you've got at least a one-to-many relationship between managers
to employees.

The basic structure would be something like this.

tblManager

Fields

MgrID - Autonumber, primary key, uniquely identifies each record

MgrName - Text, simply the managers name

MgrTel - Text (or Number), optional, telephone number for manager

If required various other fields for the manager, eg email address

tblEmployees


Fields

EmpID - Autonumber, primary key, uniquely identifies each record

MgrID - Number, foreign key from tblManager, identifies employees manager

EmpName - Text, employee name

EmpTel - Text (or Number), optional, telephone number for employee

If required various other fields for the employee, eg Social Security Number


This would be the 'standard' set up for this type of scenario.

With the tables like this it should be straightforward to set up forms etc to do what you want.
 
Upvote 0
Norie, thanks again. But this does not serve my purpose....I already have the table set it this way as i posted my inquiry.

If I have 7 textboxes and i want to show the names listed in table to show likewise in the form textboxes then what do i do?
I have set the table this way and created a form using the table but to see all the emps names in one go is not possible...

maybe it is my ignorance..but i just dont know what to do to achieve what i want:(
 
Upvote 0
Pedie

Why didn't you mention that you had it setup like this earlier?

It would have saved me a fair bit of typing.

Can you please tell us exactly how you have your tables set up?

Without knowing that anything I post will only be based on guesses/assumptions.
 
Upvote 0
I would step back - write a SQL Query that pulls the information you want.
Then you only need to get your form to use that query.

ξ

It might be:
Code:
SELECT Pedie1.Names From Pedie1;

'----------------------------------------------------------------------
I've created a very simple DB with two tables:
<a href="http://northernocean.net/etc/mrexcel/20110408_db1.zip">SAMPLE DATABASE</a>
(md5sum for zip file: 8710260583eda7c54f0564fb06ba4e84)
(sha256sum for zip file: 02a1ad6e8cf61ef7c5813eaaad393bbd3db92a1b9a9140ac2565acaff0bbc410)

In the database we have:
Table Pedie1
Table Pedie2


There is also a very simple form:
Form1


When you open the form the form's load event asks you to enter a 1 or a 2. When you enter a 1, the form's record source is set to Pedie1 (the table Pedie2). If you enter a 2 the form's record source is set to Pedie2 (the table Pedie2). If you enter anything else, the form's record source will not be set and no data will show (you will see error's in the fields instead). Scrolling through the records you will see all of the records from the table chosen (we could use a datasheet view or continuous form view to show them all at once instead of one at a time).

The code is not useful as you need to write code to get the user's name. But the principle is the same. The code in the form's load event is:
Code:
Private Sub Form_Load()
Dim s As String
Dim rsp As String

'//We will use table Pedie1 or Table Pedie2 based on user input
rsp = InputBox("Enter 1 or 2")
If IsNumeric(rsp) Then
    If rsp = 1 Then
        s = "Pedie1"
        Me.Label1.Caption = "Using Table Pedie1 "
    Else
        s = "Pedie2"
        Me.Label1.Caption = "Using Table Pedie2 "
    End If
End If
    
Me.RecordSource = s

End Sub
 
Upvote 0
I think as we've noted before, be sure to keep these tables all exactly the same as someday you probably will want to combine them all into one table. That will make for a more robust database design in the long run. I'm not really good at Access security as I don't usually have to hide anything from my database users - so it's really much more work if you are trying to keep users from seeing data (for that I would prefer a more robust database on the backend that has better control of user privileges such as SQL Server or MySQL).
 
Upvote 0
Here's a database called Employees I mocked up.

There are 2 links because there's a mdb version and an accdb version.

Can't remember which is which.:eek:

http://www.box.net/shared/7sqze3d69k

http://www.box.net/shared/e4ou14qpbz

They are exactly the same and the only code in them is for opening forms and a one line function to get the username using Environ and returns the relevant MgrID.
 
Upvote 0
Very Special thanks Xen and Norie...!!!
Thanks guys for readily helping me everytime and anytime...

Those examples are really helpful...i think i need to learn more about query.

I have so many example file lying here for it is not easy to figure out how to get one done myself...and i keep running after vba to get it done!!!


I really appriciate you help...
Thanks again!
 
Upvote 0

Forum statistics

Threads
1,225,155
Messages
6,183,212
Members
453,151
Latest member
Lizamaison

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top