Advertisement

05.07.2008 at 04:08PM PDT, ID: 23384594
[x]
Attachment Details

Code to change RecordSource property

Asked by oddintampa in Access Forms, VB Controls, Access Coding/Macros

Tags: Microsoft, Access, 2003, VBA

Hello,
I have a form (TestApptDis) which the OnOpen event triggers the RecordSource property
to find the table that equals Date() (the tables for this form are titled with dates).
The form has a combo box (cboApptDate), on the MouseDown event for the
combo box a pop-up form (frmCalPopUp) containg a Microsoft Calendar Control 11.0 (calPopUp)
appears.
When a user selects a different date on the Calendar Control, I would like
to change the RecordSource for TestApptDis. If the table does not exist the
code will create one then Requery the control.
So far I have,

Private Sub Form_Open(Cancel As Integer)
'This code works correctly opening form on correct table.
With Forms!TestApptDis
Form.RecordSource = Date
End With    
End Sub

Private Sub cboApptDate_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
'Unhide the calendar and give it the focus.
    DoCmd.OpenForm ("frmCalPopUp")
    If Not IsNull(cboApptDate) Then
    cboApptDate.Value = Forms!frmCalPopUp!calPopUp.Value
    Else
    Forms!frmCalPopUp!calPopUp.Value = Date
    End If
End Sub

Private Sub calPopUp_Click()
'Calendar opens on todays date which is the same as
'the form's RecordSource.
'User selects another date and the value is passed to the combo box.
Forms!TestApptDis!cboApptDate = Me.calPopUp
Forms!TestApptDis!cboApptDate.SetFocus
'We close the calendar form.
DoCmd.Close
End Sub

I tried this code in the combo box AfterUpdate event:

Sub cboApptDate_AfterUpdate()
Dim strNewRecordSource As String
strNewRecordSource = Me.cboApptDate.Value & "'"
Me.Form.RecordSource = strNewRecordSource
End Sub

But it didn't work, no error codes,
Does anyone have any ideas about what I might try next?
Thanks in advance,
Paul

Start Free Trial
 
Loading Advertisement...
 
[+][-]05.07.2008 at 04:13PM PDT, ID: 21521172

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.07.2008 at 04:50PM PDT, ID: 21521322

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.07.2008 at 08:52PM PDT, ID: 21522205

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Access Forms, VB Controls, Access Coding/Macros
Tags: Microsoft, Access, 2003, VBA
Sign Up Now!
Solution Provided By: omgang
Participating Experts: 1
Solution Grade: A
 
 
[+][-]05.08.2008 at 08:07AM PDT, ID: 21525389

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628