Results 1 to 8 of 8
  1. #1
    eww is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    125

    SQL vs. vba Row Source property

    I've got a subform with a control in it where I put a condition on the Row source. The Row source statement reads like this:



    SELECT tblSegments.SegmentsID, tblSegments.JobNumber, tblSegments.Segments FROM tblSegments WHERE ((tblSegments.JobNumber)=(Forms.frmProjectInfo!Job Number.Value));

    I have recently found that I need two different Main Forms with the same subform. The above doesn't work as I need a statement that more reads:

    SELECT tblSegments.SegmentsID, tblSegments.JobNumber, tblSegments.Segments FROM tblSegments WHERE ((tblSegments.JobNumber)=(Forms.frmAllProjects!JobNumber.Value));

    I know I can change Row source through the vba code based on what Main Form I am in, but I don't know what kind of notation I need. The italicized part is what I need help with.

    Private Sub sfrmSubDetStatus_Enter()
    Forms!sfrmSubDetStatus.Segment.RowSource = SELECT tblSegments.SegmentsID, tblSegments.JobNumber, tblSegments.Segments FROM tblSegments WHERE ((tblSegments.JobNumber)=(Forms.frmProjectInfo!Job Number.Value))
    End Sub

  2. #2
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    I believe it needs to be a string. Either wrap " " around it or save the string as a variable and put the variable there.

  3. #3
    eww is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    125
    would I need 2 quotation areas / 2 variables? 1 for what is being selected, 1 where it's being selected from, and 1 for the condition. Or is it all 1 variable?

  4. #4
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    they way you are referencing them does not require concatenation. If you had it as
    Me.JobNumber, for example, then yes you would need to concatenate. I believe you should be good to go with just making the whole thing one string. Give it a shot, cant hurt.

  5. #5
    eww is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    125
    Okay so I gave it a try and it's not recognizing the code, here's what I have in frmMyProjects:

    Private Sub sfrmSubDetStatus_Enter()
    Dim MyProjectSegment As Variant
    MyProjectSegment = "SELECT tblSegments.SegmentsID, tblSegments.JobNumber, tblSegments.Segments FROM tblSegments WHERE ((tblSegments.JobNumber)=(Forms.frmProjectInfo!Job Number.Value))"
    Me!sfrmSubDetStatus.Form.Refresh
    Forms!sfrmSubDetStatus.Form.Segment.RowSource = MyProjectSegment
    End Sub


    and in frmAllProjects:


    Private Sub sfrmSubDetStatus_Enter()
    Dim AllProjectSegment As Variant
    AllProjectSegment = "SELECT tblSegments.SegmentsID, tblSegments.JobNumber, tblSegments.Segments FROM tblSegments WHERE ((tblSegments.JobNumber)=(Forms.frmAllProjects!Job Number.Value))"
    Me.sfrmSubDetStatus.Form.Refresh
    Forms!sfrmSubDetStatus.Form.Segment.RowSource = AllProjectSegment
    End Sub

  6. #6
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    How would the subform like if you open another main form while one is opened?

  7. #7
    eww is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    125
    Forgive me because I'm a bit confused by your wording Weekend, but if what you're asking is what would happen if this subform was opened in two different forms at the same time...I've set it up where that can't happen. There are only these two Main forms with this subform, and they cannot be opened at the same time.

  8. #8
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    can you just link the subform to mainforms with jobnumber ? you don't need any code at all. just leave the record source of the sub form as:
    SELECT tblSegments.SegmentsID, tblSegments.JobNumber, tblSegments.Segments FROM tblSegments

Please reply to this thread with any new information or opinions.

Similar Threads

  1. the property is read only and cannot be set
    By darksniperx in forum Access
    Replies: 16
    Last Post: 11-02-2012, 02:48 PM
  2. Create Property
    By RAPSR in forum Programming
    Replies: 2
    Last Post: 10-12-2010, 12:39 AM
  3. Can Grow Property
    By chum in forum Reports
    Replies: 3
    Last Post: 01-25-2010, 11:10 AM
  4. Can Grow Property
    By MFeightner in forum Reports
    Replies: 0
    Last Post: 06-24-2009, 11:50 AM
  5. 'On Open' Property
    By emilylu3 in forum Forms
    Replies: 1
    Last Post: 12-08-2005, 02:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums