FindFirst not populating text box with results

C

CrazyHorse

Here is my problem and it may be 2 fold. I guess I am using coding from 97
which does not always seem to work with 2000.
1) My "Recordset" declaration does not seem to be valid, since it does not
capitalize the method recordset. It does not give me any errors but it is
odd that it puts it in lower case.

2) I have a form that is linked to a table. I have added a button that
prompts for userName to search for. Once found it should populate the fields
with the record located. I know the record is in there and that it finds it
since the .Nomatch is false. I have also tried bookmarks as you can see
below. Don't know what else to try.

Dim dbCurrent As Database
Dim rsUser As DAO.recordset
Set dbCurrent = CurrentDb
Set rsUser = dbCurrent.OpenRecordset("tUsers", dbOpenDynaset)

Dim user As String
Dim errormsg As String
Dim myBookMark As Variant

user = InputBox("Enter user profile to edit: ")

user = "[UserName] = '" & user & "'"
rsUser.FindFirst user
If rsUser.NoMatch = True Then
errormsg = MsgBox("User not found", vbOKOnly)
Else
Me.Refresh
myBookMark = rsUser.Bookmark
rsUser.Bookmark = myBookMark
Me.Refresh
End If
 
E

Eric Schittlipz

CrazyHorse said:
Here is my problem and it may be 2 fold. I guess I am using coding from 97
which does not always seem to work with 2000.
1) My "Recordset" declaration does not seem to be valid, since it does not
capitalize the method recordset. It does not give me any errors but it is
odd that it puts it in lower case.

2) I have a form that is linked to a table. I have added a button that
prompts for userName to search for. Once found it should populate the fields
with the record located. I know the record is in there and that it finds it
since the .Nomatch is false. I have also tried bookmarks as you can see
below. Don't know what else to try.

Dim dbCurrent As Database
Dim rsUser As DAO.recordset
Set dbCurrent = CurrentDb
Set rsUser = dbCurrent.OpenRecordset("tUsers", dbOpenDynaset)

Dim user As String
Dim errormsg As String
Dim myBookMark As Variant

user = InputBox("Enter user profile to edit: ")

user = "[UserName] = '" & user & "'"
rsUser.FindFirst user
If rsUser.NoMatch = True Then
errormsg = MsgBox("User not found", vbOKOnly)
Else
Me.Refresh
myBookMark = rsUser.Bookmark
rsUser.Bookmark = myBookMark
Me.Refresh
End If


When you are looking at the window with your coding, select Tools>References
and make sure you have a reference to Microsoft DAO 3.6 Object Library, and
remove any refernces you don't need. For example, if your coding is only
using DAO, then remove any references to Microsoft ActiveX Data Objects -
this should make sure your coding recognizes the recordset object.
However, this coding is rather longer than it needs to be if you are dealing
with a bound form. With bound forms you can make use of the RecordsetClone
property to do this:

With Me.RecordsetClone

.FindFirst "[UserName]=""Fred"""

If Not .NoMatch Then
Me.Bookmark = .Bookmark
Else
MsgBox "User not found"
End If

End With
 
L

Larry Daugherty

Be sure that the line "Option Explicit" (without the quotes) appears at the
top of each module. If it doesn't you'll have to type it in, then go to the
Tools|Options Modules tab and be sure that "Require option declaration" is
checked. Once checked any new module will have Option Explicit set.

Do you now get errors with Option Explicit set in the module in question?

Another approach would be to get rid of the command button for searching and
replace it with a combobox.

With Wizards enabled in the Toolbox; In the general area where the command
button now is, create a combobox. Tell the wizard you want to find a
record ...

When done, look at the code in the AfterUpdate event for the combobox.

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top