Full Version: Trying to set the recordsource of a form in VBA
UtterAccess Forums > Microsoft® Access > Access Forms
simoncash
Hi,
I am trying to set the recordsource of a form by using the following code which is called when a command button is clicked from the main switchboard (see below). Once the form has opened i check the recordsource and it is not being set correctly. I have also tried putting some code in the Form_Open event to do this but with no success. This is becoming really annoying. Any suggestions?
Many thx
Si
CODE
  '---------------------------------------------------------------------------------------
' Procedure : cmdAddMeeting_Click
' DateTime  : 13/08/2007 10:50
' Author    : cashsi
' Purpose   :
'---------------------------------------------------------------------------------------
'
Private Sub cmdAddMeeting_Click()
    
   On Error GoTo cmdAddMeeting_Click_Error
    DoCmd.OpenForm "frmAddMeeting", acNormal, , , acFormAdd, acWindowNormal
    
    Dim frmAddMeeting As Form
    Set frmAddMeeting = Forms!frmAddMeeting
    frmAddMeeting.RecordSource = "tblMeetings_Local"
        
   On Error GoTo 0
   Exit Sub
cmdAddMeeting_Click_Error:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmdAddMeeting_Click of VBA Document Form_frmSwitchboard"
End Sub
Ibrahim
Hi
Try the following:
Forms!frmAddMeeting.Form.RecordSource = "tblMeetings_Local"
regards,
Ibrahim
Olove Access ... it makes life easier.
dashiellx2000
I'm not entirely sure I understand why you are doing it this way.
But you could try:
CODE
Dim sourceSQL as String
sourceSQL = "SELECT * FROM tblMeetings_Local"
DoCmd.OpenForm "frmAddMeeting", acNormal, , , acFormAdd, acWindowNormal, sourceSQL

Then on the Open event of the frmAddMeeting put:
Me.Recordsource = sourceSQL
HTH.
Clippit
Did you mean:
Me.Recordsource=me.openargs
dashiellx2000
Ooops. Thanks Steve, that is exactly what I mean. I could say I was putting it in wrong to spur the OP to learn more, but I just made a boo-boo.
simoncash
Thanks guys, that was very helpful
dashiellx2000
Glad we were able to help.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.