Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old February 17th, 2006, 09:25 PM
Bill R via AccessMonster.com
Guest
 
Posts: n/a
Default Changing querydef sql to match form!control parameters

I'm trying to use the same subforms for two different mainforms. The first
main form is "frmSwaps" and the second main form is named "frmSwapsLive".
The recordsources for the subforms have parameters such as: [Forms]![frmSwaps]
![grpPayFixed]
So I have code in the On Open event of frmSwapsLive as follows:

strLive = "frmSwapsLive"
strTest = "frmSwaps"

frmName = frm.Name

If frm.Name = strLive Then blLive = True

Set db = CurrentDb
Set qdf = db.QueryDefs("qrySFrmPEData")
strSQL = qdf.SQL

If blLive Then
If InStr(strSQL, strLive) = 0 Then
strSQL = Replace(strSQL, strTest, strLive, , , vbTextCompare)
qdf.SQL = strSQL
End If
Else
If InStr(strSQL, strLive) > 0 Then
strSQL = Replace(strSQL, strLive, strTest, , , vbTextCompare)
qdf.SQL = strSQL
End If
End If

Set qdf = Nothing

I'm confident that this code will perform as advertised, but I never get
around to finding out, because before the code executes in the On Open event,
I get a series of parameter dialogs asking for "frmSwaps" parameters.

I was hoping that the qdf.sql would update before the subform had a chance to
try to run it's underlying query.

Any suggestions?

Thanks,

Bill

--
Bill Reed

"If you can't laugh at yoursel, laugh at somebody else"

Message posted via http://www.accessmonster.com



  #2  
Old February 17th, 2006, 10:35 PM
Anthony England
Guest
 
Posts: n/a
Default Re: Changing querydef sql to match form!control parameters


"Bill R via AccessMonster.com" <u9289@uwe> wrote in message
news:5c0814d230a7a@uwe...[color=blue]
> I'm trying to use the same subforms for two different mainforms. The first
> main form is "frmSwaps" and the second main form is named "frmSwapsLive".
> The recordsources for the subforms have parameters such as:
> [Forms]![frmSwaps]
> ![grpPayFixed]
> So I have code in the On Open event of frmSwapsLive as follows:
>
> strLive = "frmSwapsLive"
> strTest = "frmSwaps"
>
> frmName = frm.Name
>
> If frm.Name = strLive Then blLive = True
>
> Set db = CurrentDb
> Set qdf = db.QueryDefs("qrySFrmPEData")
> strSQL = qdf.SQL
>
> If blLive Then
> If InStr(strSQL, strLive) = 0 Then
> strSQL = Replace(strSQL, strTest, strLive, , , vbTextCompare)
> qdf.SQL = strSQL
> End If
> Else
> If InStr(strSQL, strLive) > 0 Then
> strSQL = Replace(strSQL, strLive, strTest, , , vbTextCompare)
> qdf.SQL = strSQL
> End If
> End If
>
> Set qdf = Nothing
>
> I'm confident that this code will perform as advertised, but I never get
> around to finding out, because before the code executes in the On Open
> event,
> I get a series of parameter dialogs asking for "frmSwaps" parameters.
>
> I was hoping that the qdf.sql would update before the subform had a chance
> to
> try to run it's underlying query.
>
> Any suggestions?
>
> Thanks,
>
> Bill
>
> --
> Bill Reed[/color]


You do realise that in a form/subform situation, the subform loads first,
don't you? There are a number of ways you could do this and I suppose it
depends how important it is for you to re-use the subform.
You could set the subform's recordsource to a query so it returns no
records, something like:
SELECT Null As Field1, Null As Field 2, Null As Field3 FROM MyTable WHERE
1=0
This would mean the subform opens quickly but displays no records. Then
each of the main forms can set the recordsource accordingly, eg
Me.sbfSub1.Form.Recordsource="qryLive"
or
Me.sbfSub1.Form.Recordsource="qryNotLive"



  #3  
Old February 21st, 2006, 01:35 PM
Bill R via AccessMonster.com
Guest
 
Posts: n/a
Default Re: Changing querydef sql to match form!control parameters

Anthony,

Thanks for your suggestion. I will redesign my procedure.

Bill

Anthony England wrote:[color=blue][color=green]
>> I'm trying to use the same subforms for two different mainforms. The first
>> main form is "frmSwaps" and the second main form is named "frmSwapsLive".[/color]
>[quoted text clipped - 42 lines][color=green]
>>
>> Bill[/color]
>
>You do realise that in a form/subform situation, the subform loads first,
>don't you? There are a number of ways you could do this and I suppose it
>depends how important it is for you to re-use the subform.
>You could set the subform's recordsource to a query so it returns no
>records, something like:
>SELECT Null As Field1, Null As Field 2, Null As Field3 FROM MyTable WHERE
>1=0
>This would mean the subform opens quickly but displays no records. Then
>each of the main forms can set the recordsource accordingly, eg
>Me.sbfSub1.Form.Recordsource="qryLive"
>or
>Me.sbfSub1.Form.Recordsource="qryNotLive"[/color]

--
Bill Reed

"If you can't laugh at yoursel, laugh at somebody else"

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200602/1
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,414 network members.