Thanks guys.
Randy you exactly right. That is exactly what I want to do. I did
declare my cnnThisDB and all the other variables.
My function is doing other things as well, my goal is to have that
code in my function working since I have 6 forms that will be using
this code.
This is an Inventory db, the user removes equipment so the function is
checking if equipment is assigned to a user, if it is a message box
pops up and let them know. My goal is to get the user name also in the
box so user know who it is assigned to.
Here is my function:
***Function fxEIDAssgn(plng EID As Long) As Boolean
Dim cnnThisDB As New ADODB.Connectio n
Dim rsAssignedEquip As ADODB.Recordset
Dim rsAssignedUser As ADODB.Recordset
Dim strSelectSQL As String
'set the ado connection
Set cnnThisDB = New ADODB.Connectio n
'open the ado connection to this database
cnnThisDB.Open "Driver={Micros oft Access Driver (*.mdb)};" & _
"Dbq= " & gconstrThisDb & " " & _
"Uid=admin; " & _
"Pwd=;"
'set the ado recordset to the variable
Set rsAssignedEquip = New ADODB.Recordset
Set rsAssignedUser = New ADODB.Recordset
strSelectSQL = "SELECT EID " _
& "FROM tblAssignedTo " _
& "WHERE EID = " & plngEID
'open the ado recordset
rsAssignedEquip .Open strSelectSQL, cnnThisDB
'determine if BOF and EOF are both TRUE, if so, no records exist _
for EID in tblAssignedTo. Return appropriate value
If rsAssignedEquip .BOF And rsAssignedEquip .EOF Then
fxEIDAssgn = False 'no records found matching EID
Else
fxEIDAssgn = True 'records found matching EID
End If
End Function****
I want to have the varUser variable show up in a Msgbox instead of a
text box. But I did tried using as a text box and I get the error
below same as well the Msgbox:
***Either BOF or EOF is true, or the current record has been deleted.
Requested operation requires current record.***
It works sometimes but most of the times I get the error above, BTW
the record is not deleted is there.
I have a question for you "CurrentProject .Connection.Exe cute" is that
an ADO connection?
Please let me know if you have an idea why I am getting the error
above.
Thanks a bunch.
Simone
"Randy Harris" <ra***@SpamFree .com> wrote in message news:<dz******* *************@n ewssvr28.news.p rodigy.com>...
I thought I might toss a comment in here in addition to the replies you've
already received. As Fletcher suggested it isn't very clear what you are
trying to accomplish with that function. My guessing here might miss the
mark badly.
It looks to me as though you are attempting to retrieve a single value from
the query (UserName). If that is the case there is no need to create a
recordset. Also, you mentioned that you wish to fill the TextBox based on
the click of a command button. If that is the case you could simply add
some code to the Click Event for the button.
(I'm not clear on where plngEID comes from)
(varUser is a peculiar name for a String variable)
Something like this aircode:
Private Sub MyCommand_Click ()
Dim varUser
varUser = CurrentProject. Connection.Exec ute ( _
"SELECT U.UserName " _
& "FROM tblUsers U INNER JOIN tblAssignedTo A ON U.UID = A.UID " _
& "WHERE a.EID = " & plngEID).GetStr ing
' At this point varUser should contain the name
' I like to throw away the CR GetString adds to the value
varUser = Replace(varUser , vbCR, "")
' Now push the value into your textbox
Me!MyTextBox = varUser
End Sub
Again, I'm just guessing at your requirements.
HTH
Randy Harris
"Simone" <oi****@hotmail .com> wrote in message
news:fc******** *************** ***@posting.goo gle.com... Hello
I hope you guys can help me. I am very new to ADO...
I am creating a ADODB connection in a module and trying to access it
from a command button in a form.
Function fxEIDAssgn(plng EID As Long) As Boolean
Dim rsAssignedUser As ADODB.Recordset
Dim strSelectUser As String
Dim varUser As String
Set rsAssignedUser = New ADODB.Recordset
strSelectUser = "SELECT U.UserName " _
& "FROM tblUsers U INNER JOIN tblAssignedTo A ON
U.UID = A.UID " _
& "WHERE a.EID = " & plngEID
'open the ado recordset
rsAssignedUser. Open strSelectUser, cnnThisDB
varUser = rsAssignedUser. Fields("UserNam e").Value
End Function
I would like to get the user name from the strSelectUser to show up in
a message box in my form.
I get the error "object required".
Please help.
Thanks
Simone