RecordSouce changes without instruction to (1 Viewer)

kirkm

Registered User.
Local time
Today, 14:37
Joined
Oct 30, 2008
Messages
1,257
Getting an odd result and can't quite see why

I set My Forms Record source to a Query and open the Form
Code:
Private Sub cmdEdtEntry_Click()
    Form_frmMismatchComm.RecordSource = "Select * from qryFullBB Where Prefix = '" & Me!lblThisPrefix.Caption & "';"
    StatBarPrint (Form_frmMismatchComm.RecordSource)
    DoCmd.OpenForm "frmMismatchComm", acNormal, , , , acDialog
End Sub
Sub StatBarPrint(MyString)
    Dim strReturn As String
    strReturn = SysCmd(acSysCmdSetStatus, MyString)
 End Sub
Private Sub Form_Load()
    DoCmd.MoveSize 1500, 2200, 26000, 12000
    MsgBox Me.RecordSource
End Sub
Why isn't Msgbox Me.RecordSource the same as the RecordSource assigned in Private Sub cmdEdtEntry_Click and why does the Msgbox come up twice?
 

June7

AWF VIP
Local time
Yesterday, 18:37
Joined
Mar 9, 2014
Messages
5,465
Can't set a form's RecordSource until it opens. I am surprised you don't get error message.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 19:37
Joined
Oct 29, 2018
Messages
21,453
Hi. In addition to what June7 said, I think using Form_frmMismatchComm before a DoCmd.OpenForm "frmMismatchComm" creates two separate instances of the same form.
 

kirkm

Registered User.
Local time
Today, 14:37
Joined
Oct 30, 2008
Messages
1,257
Cool, thanks folks. I'm now setting the Recordsource in the Form Load event (and now the button only opens the Form). All working as it should.


Me.RecordSource = "Select * from qryFullBB Where Prefix = '" & Form_frmMain.lblThisPrefix.Caption & "';"


That ok June?
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 19:37
Joined
Oct 29, 2018
Messages
21,453
Cool, thanks folks. I'm now setting the Recordsource in the Form Load event (and now the button only opens the Form). All working as it should.


Me.RecordSource = "Select * from qryFullBB Where Prefix = '" & Form_frmMain.lblThisPrefix.Caption & "';"


That ok June?
Hi. Just curious, what happens if you tried to use the Open (instead of Load) event to assign the Record Source?
 

kirkm

Registered User.
Local time
Today, 14:37
Joined
Oct 30, 2008
Messages
1,257
Code:
Private Sub Form_Open(Cancel As Integer)
    Me.RecordSource = "Select * from qryFullBB Where Prefix = '" & Form_frmMain.lblThisPrefix.Caption & "';"
End Sub
Private Sub cmdEdtEntry_Click()
    DoCmd.OpenForm "frmMismatchComm", acNormal, , , , acDialog
End Sub
Private Sub Form_Load()
    DoCmd.MoveSize 1500, 2200, 26000, 12000
    MsgBox Me.RecordSource
End Sub
DBGuy, It seems to work equally well
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 19:37
Joined
Oct 29, 2018
Messages
21,453
Code:
Private Sub Form_Open(Cancel As Integer)
    Me.RecordSource = "Select * from qryFullBB Where Prefix = '" & Form_frmMain.lblThisPrefix.Caption & "';"
End Sub
Private Sub cmdEdtEntry_Click()
    DoCmd.OpenForm "frmMismatchComm", acNormal, , , , acDialog
End Sub
Private Sub Form_Load()
    DoCmd.MoveSize 1500, 2200, 26000, 12000
    MsgBox Me.RecordSource
End Sub
DBGuy, It seems to work equally well
Okay. Thanks for checking and letting us know. Cheers!
 

Users who are viewing this thread

Top Bottom