Easiest question on this forum...

1jet

Registered User.
Local time
Today, 21:49
Joined
Sep 15, 2008
Messages
117
Hi all,

I'm new with VBA so please excuse me...

I know if I wanted to declare a form's text box in VBA,
I should use...

Dim frm As Form
Dim textbox As Control <--

Set frm = Forms!frmNewEmployee
Set textbox = frm.txtExampleTextbox


But what if I wanted to declare a specific table field?
Specific as in, Where Employee ID = 1?

Thanks!
 
How do you mean "declare a specific table field"?

Do you mean that you want to be able to get information from a specific field in a table?

If so then you could do something like this...
Code:
Dim db As DAO.Database
Dim rs As DAO.Recordset

Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT * FROM tblEmployee WHERE EmployeeID = 1")

If rs.EOF = False Or rs.BOF = False Then
    'To refer to a specific field you use rs("[Field Name]")
    MsgBox "Employee Name: " & rs("EmployeeName"), , "Employee"
Else
    'No results returned
End If

rs.close
set rs = Nothing
db.Close
Set db = Nothing

I hope this helps, if it wasn't what you was looking for then please say and explain further your requirements

Satal :D
 
hmmm...ive tried to edit your code to suit my application
basically my code is as follows....

it's run at the "After Update" event of combo box Forms!frmEmployeeTimesheet!cboSelectName
(even though the name shows, bound column is 1 ie Employee ID)

then this code is to be executed, running the SQL query...
SELECT Password
FROM tblEmployee
WHERE tblEmployee.[Employee ID] = "the combo box above";

this password string is then meant to appear back onto Forms!frmEmployeeTimesheet!txtPassword2

Code:
Function vbaPasswordAfterUpdate()

Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim frm As Form
Dim SelectName As Control
Dim Password As Control

Set frm = Forms!frmEmployeeTimesheet
Set SelectName = frm.cboSelectName
Set Password = frm.txtPassword2
Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT Password FROM tblEmployee WHERE tblEmployee.[Employee ID] = " & SelectName & ";")

Password.Value = rs

rs.Close
Set rs = Nothing
db.Close
Set db = Nothing

End Function
Help??
 
Function vbaPasswordAfterUpdate()
Dim frm As Form
Dim SelectName As Control
Dim Password As Control

Set frm = Forms!frmEmployeeTimesheet
Set SelectName = frm.cboSelectName
Set Password = frm.txtPassword2

Password.Value = Dlookup("[Password]","tblEmployee","[Employee ID] = " & SelectName)

End function
 
Function vbaPasswordAfterUpdate()
Dim frm As Form
Dim SelectName As Control
Dim Password As Control

Set frm = Forms!frmEmployeeTimesheet
Set SelectName = frm.cboSelectName
Set Password = frm.txtPassword2

Password.Value = Dlookup("[Password]","tblEmployee","[Employee ID] = " & SelectName)

End function

THATS IT?!!?

thanks buddy.....i can close my books and stop reading about DAO and ADO's
 

Users who are viewing this thread

Back
Top Bottom