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_Click()
On Error GoTo Err_cmdDeptsForAd_Click
Dim strDocName As String
Dim strLinkCriteria As String
Dim lngAdKey As Long
If IsNull(Me.lstAds.Column(0)) Then
MsgBox "Please choose an ad"
GoTo Exit_cmdDeptsForAd_Click
Else
lngAdKey = Me.lstAds.Column(0)
End If
strDocName =
"frmSelDeptsForAd","Forms!frmSelDeptsForAd!cboAdKe y.Value =" & lngAdKey
'Have tried many forms of this line of code - nothing worked so far
DoCmd.OpenForm strDocName
Exit_cmdDeptsForAd_Click:
Exit Sub
Err_cmdDeptsForAd_Click:
MsgBox Err.Number & " " & Err.Description
Resume Exit_cmdDeptsForAd_Click
End Sub
"Forms!frmSelStoresForAd!cboAdKey.Value =" & lngAdKey 7 12203
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_Click() On Error GoTo Err_cmdDeptsForAd_Click
Dim strDocName As String Dim strLinkCriteria As String Dim lngAdKey As Long
If IsNull(Me.lstAds.Column(0)) Then MsgBox "Please choose an ad" GoTo Exit_cmdDeptsForAd_Click Else lngAdKey = Me.lstAds.Column(0) End If
strDocName = "frmSelDeptsForAd","Forms!frmSelDeptsForAd!cboAdKe y.Value =" & lngAdKey 'Have tried many forms of this line of code - nothing worked so far
DoCmd.OpenForm strDocName
Exit_cmdDeptsForAd_Click: Exit Sub
Err_cmdDeptsForAd_Click: MsgBox Err.Number & " " & Err.Description Resume Exit_cmdDeptsForAd_Click
End Sub "Forms!frmSelStoresForAd!cboAdKey.Value =" & lngAdKey
The format is
Docmd.OpenForm "FormName",,,"Dept = " & 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.OpenArgs) 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.lstAds.Column(0)) Then
MsgBox "Please choose an ad"
GoTo Exit_cmdDeptsForAd_Click
Else
lngAdKey = Me.lstAds.Column(0)
End If
strDocName = "frmSelDeptsForAd"
DoCmd.OpenForm strDocName, , , , , ,
"Forms!frmSelDeptsForAd!cboAdKey"
On the SelectDepts form On Open event:
Private Sub Form_Open(Cancel 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.OpenArgs) 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!frmSelDeptsForAd!cboAdKey"
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.OpenArgs) 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.lstAds.Column(0)) Then MsgBox "Please choose an ad" GoTo Exit_cmdDeptsForAd_Click Else lngAdKey = Me.lstAds.Column(0) End If
strDocName = "frmSelDeptsForAd" DoCmd.OpenForm strDocName, , , , , , "Forms!frmSelDeptsForAd!cboAdKey"
On the SelectDepts form On Open event: Private Sub Form_Open(Cancel 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.OpenArgs) 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!frmSelDeptsForAd!cboAdKey"
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!frmSelDeptsForAd!cboAdKey". 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!frmSelDeptsForAd!cboAdKey".
The following.
DoCmd.OpenForm strDocName, , , "AdKey = " & _
"Forms!frmSelDeptsForAd!cboAdKey"
Is also incorrect, unless you have an adkey value equal to the string
"Forms!frmSelDeptsForAd!cboAdKey".
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 = "frmSelDeptsForAd"
strLinkCriteria = "[AdKey] = " & AdKey
DoCmd.OpenForm strDocName, , , , , , AdKey
Code for Second form: (frmSelDeptsForAd)
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |