This code very efficiently displays all records from a MaketTable query and displays them in a large texbox separated with vbNewline & vbnewline
for easier reading:
An image of this does is below. How would a button be coded to tell Access that every time
the Next button is clicked it moved to the next record - in Textbox1. It would have to read
Len of the text, add two spaces for vbnewline & vbnewline. If correct the cursor should be on
the first line of the next record(paragraph)(verse)
Have never worked with the Len statement before, and still not sure if this is the bes way to
achieve this.
Any guidance and help would be greatly appreciated. Image below are records which each Next button click
would advance to
for easier reading:
Code:
Private Sub cmdTestCode_Click()
Dim x As String
Dim rs As Recordset
Dim db As Database
Dim strSQL As String
Dim srchval As String
x = Me.txtSearchCriteria.Value
srchval = Me.txtSearchCriteria.Value
With DoCmd
.SetWarnings False
.OpenQuery "qmakSearch" 'qmakSearch is a make table query that must exist on the Db
.SetWarnings True
End With
If DCount("*", "tblSearchResults") > 0 Then 'tblSearchResults is the MakeTable created table from qmkSearch query
Me.Controls("txtMatchedVerses").Value = "" 'Clear - Note txtMatchedVerses is the name of the text box thta must exist on the form to receive the results of the SQL query.
strSQL = "SELECT * FROM tblSearchResults;"
Set db = CurrentDb: Set rs = db.OpenRecordset(strSQL)
rs.MoveFirst
Do Until rs.EOF
Me.Controls("txtMatchedVerses").Value = IIf(Len(Me.Controls("txtMatchedVerses").Value) = 0, rs.Fields(0).Value, Me.Controls("txtMatchedVerses").Value & vbNewLine & vbNewLine & rs.Fields(0).Value)
rs.MoveNext
Loop
Set rs = Nothing: Set db = Nothing
MsgBox "There were " & DCount("*", "tblSearchResults") & " records found.", vbInformation
Else
MsgBox "There were no records found.", vbExclamation
End If
Me.Totrows = DCount("*", "tblSearchResults")
End Sub
the Next button is clicked it moved to the next record - in Textbox1. It would have to read
Len of the text, add two spaces for vbnewline & vbnewline. If correct the cursor should be on
the first line of the next record(paragraph)(verse)
Have never worked with the Len statement before, and still not sure if this is the bes way to
achieve this.
Any guidance and help would be greatly appreciated. Image below are records which each Next button click
would advance to