I have a form where the user selects an item from a list box, and then
works on that item. The user chooses an AD, then opens a form to
assign departments to the ad. The top of the Depts form has a combo
box, to select an ad from the drop down list.
I would like the Depts form to open with the Ad selected on the Main
form displaying in the combo box, AND any information already added
presented to the user. (I am thinking this latter part would be a
requery of the combo box or something).
My problem is that I can't get the frmDeptsForAd to open with a value
in the combo box.
Perhaps my form design/approach is wrong. I have a combo box at the
top so the user can update any ad without going back to the main form.
Thanks!
sara
Code:
Private Sub cmdDeptsForAd_C lick()
On Error GoTo Err_cmdDeptsFor Ad_Click
Dim strDocName As String
Dim strLinkCriteria As String
Dim lngAdKey As Long
If IsNull(Me.lstAd s.Column(0)) Then
MsgBox "Please choose an ad"
GoTo Exit_cmdDeptsFo rAd_Click
Else
lngAdKey = Me.lstAds.Colum n(0)
End If
strDocName =
"frmSelDeptsFor Ad","Forms!frmS elDeptsForAd!cb oAdKey.Value =" & lngAdKey
'Have tried many forms of this line of code - nothing worked so far
DoCmd.OpenForm strDocName
Exit_cmdDeptsFo rAd_Click:
Exit Sub
Err_cmdDeptsFor Ad_Click:
MsgBox Err.Number & " " & Err.Description
Resume Exit_cmdDeptsFo rAd_Click
End Sub
"Forms!frmSelSt oresForAd!cboAd Key.Value =" & lngAdKey 7 12241
sara wrote: I have a form where the user selects an item from a list box, and then works on that item. The user chooses an AD, then opens a form to assign departments to the ad. The top of the Depts form has a combo box, to select an ad from the drop down list.
I would like the Depts form to open with the Ad selected on the Main form displaying in the combo box, AND any information already added presented to the user. (I am thinking this latter part would be a requery of the combo box or something).
My problem is that I can't get the frmDeptsForAd to open with a value in the combo box.
Perhaps my form design/approach is wrong. I have a combo box at the top so the user can update any ad without going back to the main form.
Thanks! sara
Code: Private Sub cmdDeptsForAd_C lick() On Error GoTo Err_cmdDeptsFor Ad_Click
Dim strDocName As String Dim strLinkCriteria As String Dim lngAdKey As Long
If IsNull(Me.lstAd s.Column(0)) Then MsgBox "Please choose an ad" GoTo Exit_cmdDeptsFo rAd_Click Else lngAdKey = Me.lstAds.Colum n(0) End If
strDocName = "frmSelDeptsFor Ad","Forms!frmS elDeptsForAd!cb oAdKey.Value =" & lngAdKey 'Have tried many forms of this line of code - nothing worked so far
DoCmd.OpenForm strDocName
Exit_cmdDeptsFo rAd_Click: Exit Sub
Err_cmdDeptsFor Ad_Click: MsgBox Err.Number & " " & Err.Description Resume Exit_cmdDeptsFo rAd_Click
End Sub "Forms!frmSelSt oresForAd!cboAd Key.Value =" & lngAdKey
The format is
Docmd.OpenForm "FormName",,,"D ept = " & Me.Combo
Here's another method
Docmd.OpenForm "FormName",,,,, ,Me.Combo
What's the difference? The first opens the form and filters to what you
have passed.
The second opens the form with an argument. In your events you can then
use the value by looking at what is contained in OpenArgs in the second
form. Ex:
If not isnull(Me.OpenA rgs) then
Me.Filter = "Dept = " & Me.OpenArgs
Me.FilterOn = True
Me.Combo = Me.OpenArgs
Endif
Thanks, Salad - but I don't quite have it yet. I'm still quite new at
all this coding (Sorry - didn't mention this at first).
Here's the code I tried: From the Main form:
If IsNull(Me.lstAd s.Column(0)) Then
MsgBox "Please choose an ad"
GoTo Exit_cmdDeptsFo rAd_Click
Else
lngAdKey = Me.lstAds.Colum n(0)
End If
strDocName = "frmSelDeptsFor Ad"
DoCmd.OpenForm strDocName, , , , , ,
"Forms!frmSelDe ptsForAd!cboAdK ey"
On the SelectDepts form On Open event:
Private Sub Form_Open(Cance l As Integer)
' If the user came from the main form and selected an ad, put that ad
in the combo box
If Not IsNull(Me.OpenA rgs) Then
Me.Filter = "Dept = " & Me.OpenArgs
Me.FilterOn = True
Me.cboAdKey = Me.OpenArgs
End If
End Sub
And the first way (I commented out the On Open event code for this
try):
DoCmd.OpenForm strDocName, , , "AdKey = " &
"Forms!frmSelDe ptsForAd!cboAdK ey"
I managed to get the quotes, and format the parameter properly, at
least I got it to compile. But when the SelDepts form opens, the combo
box is still blank. Can you see what I'm missing?
thanks - I relaxed quite a bit when I saw your response - Help is here!
sara
This is pretty simple. Use the OpenArgs Property of the form. In the
main form add something like this to a command button:
Private Sub Command4_Click( )
DoCmd.Openform "Form4", acNormal, , , , , comboAD
End Sub
Then in the Dept form - in the Load or Open event you can do this:
Private Sub Form_Load()
ComboDept = Me.OpenArgs
End Sub
You can spruce this up a bit by checking for null values in openargs
first:
If Not IsNull(Me.OpenA rgs) Then
ComboDept = Me.OpenArgs
End IF
Rich
*** Sent via Developersdex http://www.developersdex.com ***
sara wrote: Thanks, Salad - but I don't quite have it yet. I'm still quite new at all this coding (Sorry - didn't mention this at first).
Here's the code I tried:
From the Main form: If IsNull(Me.lstAd s.Column(0)) Then MsgBox "Please choose an ad" GoTo Exit_cmdDeptsFo rAd_Click Else lngAdKey = Me.lstAds.Colum n(0) End If
strDocName = "frmSelDeptsFor Ad" DoCmd.OpenForm strDocName, , , , , , "Forms!frmSelDe ptsForAd!cboAdK ey"
On the SelectDepts form On Open event: Private Sub Form_Open(Cance l As Integer)
' If the user came from the main form and selected an ad, put that ad in the combo box
If Not IsNull(Me.OpenA rgs) Then Me.Filter = "Dept = " & Me.OpenArgs Me.FilterOn = True Me.cboAdKey = Me.OpenArgs End If
End Sub
And the first way (I commented out the On Open event code for this try): DoCmd.OpenForm strDocName, , , "AdKey = " & "Forms!frmSelDe ptsForAd!cboAdK ey"
I managed to get the quotes, and format the parameter properly, at least I got it to compile. But when the SelDepts form opens, the combo box is still blank. Can you see what I'm missing?
thanks - I relaxed quite a bit when I saw your response - Help is here! sara
In your second forms OnOpen event...to see what you passed...you could
enter a line like
msgbox "Openargs = " & Me.OpenArgs
and it will display what you sent to it...or nothing but a blank msgbox
if null.
I expect it would show "Forms!frmSelDe ptsForAd!cboAdK ey". That's not
what you want.
Your code to open the form should be something like
DoCmd.OpenForm strDocName, , , , , ,Me.cboAdKey
This passes the value, not the string "Forms!frmSelDe ptsForAd!cboAdK ey".
The following.
DoCmd.OpenForm strDocName, , , "AdKey = " & _
"Forms!frmSelDe ptsForAd!cboAdK ey"
Is also incorrect, unless you have an adkey value equal to the string
"Forms!frmSelDe ptsForAd!cboAdK ey".
Here is a hint. Strings are surrounded in ". Date in #. Number in
nothing. Ex:
str = "Smith"
dat = #1/1/2006#
num = 2
"LastName = """ & strt & """
or
"Lastname = '" & str & "'"
"StartDate = #" & dat & "#"
"Qty = " & num
Basically, the "where" clause you pass in the Docmd.Openform is like a
SQL whereclause without the word "Where".
Hope this gets you a bit further.
Salad - (and Rich P, too!)
Sorry for the delay - I was out for a week.
I have (again) tried to make this work and am still not there. I think
one problem may be about OpenArgs. Do I declare that somehow? I
checked other posts and it appears Args was declared as a string, but
then how does Me.OpenArgs work? Me.OpenArgs is always null for me - no
matter which code I have tried.
Summary of what I've learned through reading (I have finally gotten my
Access Help fixed): - Maybe I have misunderstood something here?
OpenArgs is only available with DoCmd.OpenForm, which I'm using.
OpenArgs is the last parameter of the OpenForm method (which explains
the ",,,," in your code for me.
You use either OpenArgs or Where condition (as you showed above)
So, I am baffled as to why I am not seeing the OpenArgs in my msgbox
(and why the ad it not showing up in the drop down box)
Code for calling form:
AdKey = Me.txtAdKey
strDocName = "frmSelDeptsFor Ad"
strLinkCriteria = "[AdKey] = " & AdKey
DoCmd.OpenForm strDocName, , , , , , AdKey
Code for Second form: (frmSelDeptsFor Ad)
Private Sub Form_Load()
On Error GoTo Err_Form_Load
Set mdb = CurrentDb
Set mqdf = New DAO.QueryDef
Me.cboAdKey = Me.OpenArgs
MsgBox "OpenArgs = " & Me.OpenArgs
Thanks for bearing with me on this one. Your comments make it look so
doable, but I'm just not getting it!
sara
Hi sara,
You might try something real basic/simple.
In the mainform under some button, just open a form
DoCmd.OpenForm "Form2", acNormal, , , , , "testing"
Note: I am using the constant acNormal. You might try that also.
Then in the form you open - in the Form_Load event
MsgBox Me.OpenArgs
I just did this without any issues. I got the message box with
"testing" as text on the open event of Form2.
Rich
*** Sent via Developersdex http://www.developersdex.com ***
Thanks. I got it! I don't know why I couldn't do it before, but I am
now all set. Couldn't have done it without your (and Salad's) generous
help.
Moving on to my next issue.
Again, thank you!
Sara This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Richard |
last post by:
Hi,
I have a form based on a table. When I filter the form I want to run a
report based on the same table with the same filter as the form. No problem
until I want to filter a combo box where the text value is on a different
table. The me.filter is then a text instead of the id-number from the lookup
table. This causes the report to prompt...
|
by: Caesar Augustus |
last post by:
Greetings all!
Before I ask a question I will try to provide a little background. I
am currently working on an app(PD) that is essentially a search engine
to find specific records. Once the record is found and data is
verified, the user transfers it to another pre-existing
application(AP).
Front end for both apps is Access 97 while the...
|
by: Todd |
last post by:
My form contains a combo box and the "not in list" event is triggerred when
the user enters a value that is not among the values listed in the combo
box. I want the user to be able to add a new value (which is fairly easy to
do) but here's the twist...
The form that allows the user to enter the new value exists in a separate
Access...
|
by: Neil Ginsberg |
last post by:
OK, this is a stupid thing, but I can't seem to get this to work. I have a
form with a subform (in continuous form view). A combo box on the main form
has code in the AfterUpdate event which adds a record to the subform (based
on the value of the combo box) and requeries the subform control. I want the
focus to return to the combo box on the...
|
by: Zlatko Matić |
last post by:
There is a form (single form) and a combobox. I want that current record of
the form is adjusted according to selected value in the combobox. Cuurrent
record should be the same as the value in the combobox.
What is the solution?
Thank you in advance.
| |
by: dufnobles via AccessMonster.com |
last post by:
I have a form that displays a dropdown box. The options in the drop down
vary according to a value queried from a database boolean (Yes/No) field. I
would like to do the following:
If the boolean value is True, then the dropdown options will be option1 and
option2.
If the boolean value is False, then the dropdown box will contain:...
|
by: omar.norton |
last post by:
I am trying to create a from with a series of combo boxes that each
query a different field (called Specific01, Specific02 etc., except
the first field which is called Condition). Each combo box has a SQL
statement in it's rowsource so it will only display distinct records
in it's field where all the previous fields match the choices chosen...
|
by: abhishekbrave |
last post by:
The code below is opening a calendar on mouse over in the same window.
I need the calendar to be opened in new window.
Have to fulfill this requirement urgentely so posting the whole code here.
I tried doing some workaround using window.open() but not getting the calendar in new window.
<html>
<head>
<script language="JavaScript">
|
by: casan.mike |
last post by:
Hi all,
I have a form called "customer_frm" with many records in it.
I would like to have a form that has a combobox listing all the
customers, and a button that open the "customers_frm" to the specific
record I have chosen in the combobox.
I could do this through the Search function of access, however it is
not really friendly for...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |