Requery subform from command button (1 Viewer)

roscoe10s

New member
Local time
Today, 17:58
Joined
Jun 14, 2021
Messages
6
First I apologize for what must be a fundamental question that has been answered many a time. I have read over a dozen posts in this forum about this and am using the suggested methods.

Code:
Dim strSQL As String

strSQL = "SELECT tblPOS_Import_Prelim.* From tblPOS_Import_Prelim ORDER BY tblPOS_Import_Prelim.Dist_Name, tblPOS_Import_Prelim.Shipment_Date, tblPOS_Import_Prelim.Bill_To_Name;"

Me.frmPOSPreview.Form.RecordSource = strSQL
Me.frmPOSPreview.Form.Requery

This code is executed from a command button - straightforward "preview data" thinking and a simple query, set to the RecordSource of an unbound subform. Upon clicking the button, the subform changes from a blank space to what would appear to be a results query, as I can see the record selectors. However, there is no data being displayed (yes, there is data in the referenced table).

The odd thing is that I am using almost exactly the same code in a different database except the execution is from a toggle box/radio button selection. Zero errors or issues. I've compared the property sheets of the two forms and subforms and examined both sets of code. I cannot figure out where the obvious error is.

Second, I apologize if you don't see a reply or thanks - my attempts to do so on a previous thread were getting blocked as Spam-like or possible inappropriate content. So please know I appreciate your assistance and at some point, I'll figure out how to reply to posts to say thanks.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 22:58
Joined
Jul 9, 2003
Messages
16,245
Try:-

Code:
Me.frmPOSPreview.Form.RecordSource = strSQL
Me.frmPOSPreview.Requery
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:58
Joined
May 7, 2009
Messages
19,169
the form is Unbound therefore you must Bind each
Textbox on the Form to the Field in your RecordSource:

Code:
Dim ctl As Control
With Me.frmPOSPreview.Form
    .RecordSource = strSQL
    'assumming the textboxname is same as the fieldname
    For Each ctl In .Controls
        If Typeof ctl Is Textbox Then
            ctl.ControlSource = ctl.Name
        End If
    Next
End With
 

Users who are viewing this thread

Top Bottom