Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / May 2008

Tip: Looking for answers? Try searching our database.

ADO Access Problem from Form

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Christoph - 24 May 2008 00:52 GMT
Hi,

I'm currently faced with the following problem:

I have a form "frmBasic" that has three text boxes txt1, txt2 and
txt3. They hold respectively, last name, first name and city.

I would like for the user to be able to enter just a last name in
txt1, then click a button cmdSearch that will then pull all records
out of the table that have the last name as specified in txt1. If
there are more than one record, the first record is to be displayed.
So far so good, I was able to achieve this with the following:

Private Sub cmdSearch_Click()

   tbl = "tblInsuredsBasic"

   Set rs = New ADODB.Recordset

   strSQL = "SELECT * FROM tblInsuredsBasic " _
       & "WHERE [LastName] = '" & Me.txt1 & "'"

   rs.Open strSQL, CurrentProject.Connection, adOpenDynamic,
adLockOptimistic

   With rs

       Me.txt1 = ![LastName]
       Me.txt2 = ![FirstName]
       Me.txt3 = ![City]

   End With

ExitHere:
   Exit Sub

HandleError:
   MsgBox Err.Description
   Resume ExitHere

End Sub

What I can't get to work is this: I have one more button named
cmdFWD.
If the query above results in more than one records, I would like to
advance to the next record by clicking the cmdFF button and then
display that next record. I have rs defined with "Dim rs As
ADODB.Recordset" outside of all subs, at the very beginning of the
form module. How can I keep my pointer/reference to the recordset
pulled with the sub above and then process it in another sub? The
ultimate goal is to develop my own record navigation buttons.
However,
it seems everytime the code exits the cmdSearch_Click() procedure, it
loses all references to the data.

Thanks very much for any help.

Christoph
Damon Heron - 24 May 2008 22:20 GMT
Here is a way to make it simple.  Add a subform to your main form, with the
recordsource the tblInsuredsBasic .  forget the txtbox on mainform, just
have a command button, with this code:

Private Sub Command1_Click()
On Error GoTo Err_Command1_Click
Dim strsql As String
strsql = "Select * from tblInsuredsBasic where tblInsuredsBasic.LastName =
[?]"
Me!subfrmName.Form.RecordSource = strsql

Exit_Command1_Click:
   Exit Sub

Err_Command1_Click:
   MsgBox Err.Description
   Resume Exit_Command1_Click

End Sub

The subform will show all the records with last name = to what the user
entered on parameter box.

Damon

> Hi,
>
[quoted text clipped - 54 lines]
>
> Christoph
Damon Heron - 24 May 2008 22:27 GMT
If you want to keep the textbox on the mainform, for whatever reason, change
the sql statement to:
strsql = "Select * from tblInsuredsBasic where tblInsuredsBasic.LastName ="
& "'" & Me.txt1 & "'"
Damon

> Here is a way to make it simple.  Add a subform to your main form, with
> the recordsource the tblInsuredsBasic .  forget the txtbox on mainform,
[quoted text clipped - 20 lines]
>
> Damon
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.