[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

MS Access - Docmd.Openform pass a variable

Posted on 2013-12-11
8
Medium Priority
?
3,268 Views
Last Modified: 2013-12-11
Hello all!
Using MS Access 07

I have a Form where if the user clicks a control button I have it Open a 2nd form.  

On that 2nd Form there are two Unbound combo boxes that the user selects a State or County to filter  info on that 2nd form.  

That same State and County had already selected on the 1st Form (also in unbound combo boxes) before they clicked on the control button.

The 2nd Form is Not a subform of the 1st.  It is an independent form.

On both Forms the Unbound State combo box is named "cboSelectState" and the Unbound County combo box is named "cboSelectCounty"

My OnClick event on the 1st Form is

Private Sub cmdAddStateCountyBkType_Click()
Dim lngState As Long, lngCountyCode As Long
lngState = Me.cboSelectState.Column(0)
lngCountyCode = Me.cboSelectCounty.Column(0)

    DoCmd.OpenForm "frmSys_ValidCountyCodeBookType", , "[cboSelectState]=" & lngState & "," & "[cboSelectCounty]=" & lngCountyCode    

End Sub

Open in new window


It opens the Form correctly but it doesn't update those two combo boxes on the 2nd from with the info I'm trying to pass to it.
0
Comment
Question by:wlwebb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 1000 total points
ID: 39710931
The OpenForm method takes several arguments. You're using the WHERE argument in your example, which will not update or modify your combos.

To do that, you can use the OpenArgs argument, or just refer to the other form directly if you always want the combos on  frmSys_ValidCountyCodeBookType to always show the values from the first form.

To use OpenArgs, you'd change the OpenForm to this:

DoCmd.OpenForm "frmSys_ValidCountyCodeBookType", , , , , , lngState & ";" & lngCountryCode

Open in new window

This would pass in two values, separated by a semicolon.

Now in the Open or Load event of frmSys_ValidCountyCodeBookType:

If Nz(Me.OpenArgs, "") <> "" Then
  If Instr(0, Me.OpenArgs, ";") > 0 Then
    Dim arr() As String
    arr() = Split(Me.OpenArgs, ";")

    Me.cboSelectState= arr(0)
    Me.cboCountryCode= arr(1)
  End If
End If

Open in new window

Assuming the values exist in those combos, this should set them to the values you pass in.
0
 
LVL 61

Assisted Solution

by:mbizup
mbizup earned 1000 total points
ID: 39710932
The WHERE condition is for filtering data in the form's recordsource, not for setting control values, and does not affect unbound controls.  Try this instead:
Private Sub cmdAddStateCountyBkType_Click()
Dim lngState As Long, lngCountyCode As Long
lngState = Me.cboSelectState.Column(0)
lngCountyCode = Me.cboSelectCounty.Column(0)

    DoCmd.OpenForm "frmSys_ValidCountyCodeBookType"
       Forms!frmsys![cboSelectState]=  lngState 
       Forms!frmSys![cboSelectCounty]= ngCountyCode    

End Sub

Open in new window

0
 

Author Comment

by:wlwebb
ID: 39710943
LSM...
I get a Run-Time Error "5"
Invalid procedure call or argument.
it's stopping on
  If InStr(0, Me.OpenArgs, ";") > 0 Then

when I hover over the "OpenArgs" in the first line I do see the correct cbo codes from the 1st form...... ????
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 85
ID: 39710949
Sorry, my .NET is showing :)

Change that line to this:

If InStr(1, Me.OpenArgs, ";") > 0 Then
0
 

Author Comment

by:wlwebb
ID: 39710952
Mbiz....
That works for passing the State.....

However, on the County it isn't working.  That's because my combo box rowsource for the County is updated from the AfterUpdate event of the cboSelectState combo box.....

Since the Rowsource isn't within the Rowsource of that combobox but is in the VB code can I get there?
0
 

Author Comment

by:wlwebb
ID: 39710955
LSM....
Well that works for the State, but like my response to Mbiz just above, my Rowsource code for the SelectCounty combobox is in VB code of the AfterUpdate event of the SelectState......  so the passing of that argument doesn't see any rowsource....

Is there a way around?
0
 

Author Comment

by:wlwebb
ID: 39710960
NEVER MIND..........

Got it....  I just copy and inserted the "SELECT" code for the RowSource from the CboSelectState just before the "me.cboselectCounty = arr(1)" coding
0
 

Author Closing Comment

by:wlwebb
ID: 39710963
Thanks LSM and MBiz.......

I tried both methods and they both worked!!!!!!!  I gave you each equal amounts of points because both worked and both were posted extremely quickly after I posted the question

THANK YOU
0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question