473,779 Members | 2,023 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Combobox does not show the correct value

111 New Member
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2. Combo34.SetFocus
  3. If DLookup("[Permission]", "RadioLog_tblValUsers", "[UserName]= '" & [Forms]![frmLogin]![txtUsername] & "'") = "mngr" Then
  4.  
  5.     If DLookup("[RegionID]", "RadioLog_tblValUsers", "[UserName]= '" & [Forms]![frmLogin]![txtUsername] & "'") = 1 Then
  6.         Me.Combo32.RowSourceType = "Table/Query"
  7.         Me.Combo32.RowSource = "qryRegion1"
  8.             Else
  9.     If DLookup("[RegionID]", "RadioLog_tblValUsers", "[UserName]= '" & [Forms]![frmLogin]![txtUsername] & "'") = 2 Then
  10.         Me.Combo32.RowSourceType = "Table/Query"
  11.         Me.Combo32.RowSource = "qryRegion2"
  12.     Else
  13.     If DLookup("[RegionID]", "RadioLog_tblValUsers", "[UserName]= '" & [Forms]![frmLogin]![txtUsername] & "'") = 3 Then
  14.         Me.Combo32.RowSourceType = "Table/Query"
  15.         Me.Combo32.RowSource = "qryRegion3"
  16.     End If
  17.     End If
  18.     End If
  19.  
  20. Else
  21. If DLookup("[Permission]", "RadioLog_tblValUsers", "[UserName]= '" & [Forms]![frmLogin]![txtUsername] & "'") = "spvr" Then
  22.          Me.Combo32.RowSourceType = "Table/Query"
  23.         Me.Combo32.RowSource = "qryHQ"
  24. Else
  25. If DLookup("[Permission]", "RadioLog_tblValUsers", "[UserName]= '" & [Forms]![frmLogin]![txtUsername] & "'") = "user" Then
  26.         Me.Combo32.RowSourceType = "table/query"
  27.         Me.Combo32.RowSource = "qryDistrictDefaultUser"
  28.         Me.Combo32.DefaultValue = DLookup("[DistrictID]", "RadioLog_tblValUsers", "[UserName]= '" & [Forms]![frmLogin]![txtUsername] & "'")
  29.         Me.Combo32.Locked = True
  30. Else
  31.         Me.Combo32.RowSourceType = "Table/Query"
  32.         Me.Combo32.RowSource = "RadioLog_tblValDistrict"
  33. End If
  34. End If
  35. End If
  36.  
  37. End Sub
  38.  
I have above code written which sets the row source property for combo34(Distric tID). I use this code because the value of this combobox should be different for different users. .The form is bound to the table called RadioCallActivi ty.
Question:
Suppose I logged in as a staff user, I can see the records entered by another people but the Combo34(Distric tID) is blank. It does not show any values in it.
How to fix it?
Thanks
Dec 14 '09 #1
22 3318
missinglinq
3,532 Recognized Expert Specialist
Is the form frmLogIn open when this code is run?

What version/service pack are you running? Version 2003 with the SP3 service pack installed can have "disappeari ng" data if the subsequent hotfix is not applied,

Linq ;0)>
Dec 14 '09 #2
AccessBeetle
111 New Member
I am using SP 2. The form frmLogin is open but hidden. Is there anything else I have to consider to make it work?
THanks
Dec 14 '09 #3
Megalog
378 Recognized Expert Contributor
This is a bit confusing, especially all the nested If's..
So this works, except if you're a 'staff user'? What permission is that exactly, 'user'? If so, then your problem might be the 'Me.Combo32.Def aultValue' should be changed to 'Me.Combo32.Val ue' (in line 22)

Few suggestions by the way....

First, here's a modified version of what you posted, using ElseIf instead of all the extra If statements:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2.     Combo34.SetFocus
  3.     Dim txtPermission As String
  4.     Dim lngRegion As Long
  5.  
  6.     txtPermission = DLookup("[Permission]", "RadioLog_tblValUsers", "[UserName]= '" & [Forms]![frmLogin]![txtUsername] & "'")
  7.     lngRegion = DLookup("[RegionID]", "RadioLog_tblValUsers", "[UserName]= '" & [Forms]![frmLogin]![txtUsername] & "'")
  8.  
  9.     Me.Combo32.RowSourceType = "Table/Query"
  10.     If txtPermission = "mngr" Then
  11.         If lngRegion = 1 Then
  12.             Me.Combo32.RowSource = "qryRegion1"
  13.         ElseIf lngRegion = 2 Then
  14.             Me.Combo32.RowSource = "qryRegion2"
  15.         ElseIf lngRegion = 3 Then
  16.             Me.Combo32.RowSource = "qryRegion3"
  17.         End If
  18.     ElseIf txtPermission = "spvr" Then
  19.         Me.Combo32.RowSource = "qryHQ"
  20.     ElseIf txtPermission = "user" Then
  21.         Me.Combo32.RowSource = "qryDistrictDefaultUser"
  22.         Me.Combo32.DefaultValue = DLookup("[DistrictID]", "RadioLog_tblValUsers", "[UserName]= '" & [Forms]![frmLogin]![txtUsername] & "'")
  23.         Me.Combo32.Locked = True
  24.     Else
  25.         Me.Combo32.RowSource = "RadioLog_tblValDistrict"
  26.     End If
  27.  
  28. End Sub
Also, this login form should be placing all these values into global variables, instead of you having to call on the specific form itself everytime with the Dlookups.
Dec 14 '09 #4
AccessBeetle
111 New Member
user=staff user. they are same. Tried to using global variables but there was an error I could not solve so I replaced it with this chunk of code.
Also, user and staff user are same.
No, If I logged in as a mngr (of region 2: Districts 1,2,3,4,5), it will show every details of the previously entered records but the DistrictID. The combobox is blank. but it will show every detail, including DistrictID, for the records where DistrictID =1 or 2 or 3 or 4 or 5
I hope you understand.
Thanks for suggestions anyways!!
Dec 14 '09 #5
Megalog
378 Recognized Expert Contributor
I'd doublecheck the queries that you're assigning to the combo box to make sure they are correctly filtering your results.

Open them up in design view, specify the criteria manually (your region #'s), and make sure the data being returned is valid.

Also, in 'qryDistrictDef aultUser', make sure the first column (or whichever column you're binding your combo box to) is also the DistrictID
Dec 14 '09 #6
AccessBeetle
111 New Member
They are filtering records correctly.I checked it yet once more.
Also, in 'qryDistrictDef aultUser', make sure the first column (or whichever column you're binding your combo box to) is also the DistrictID
what does this mean?
Dec 14 '09 #7
AccessBeetle
111 New Member
Could it be a problem as this code is written in Form's open event?
Which event takes place when you exactly start to enter data?
Dec 14 '09 #8
Megalog
378 Recognized Expert Contributor
You can try shifting it to the Load event, instead of Open. And maybe remove the SetFocus command in the first line. Although I'm not sure either move will help.

The sequence of events goes:
Open - The form isnt bound to the recordset yet, this is only creating the controls
Load - Form is bound to the dataset
Current - This is triggered when loading the first record, AND everytime you move to a new record
Dec 14 '09 #9
AccessBeetle
111 New Member
You were right. None of it helped? I don't where should I see for it??
Dec 15 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

7
8530
by: Nicolae Fieraru | last post by:
Hi All, I am trying to change the rowsource of a combobox when I click on it. I played with many events, associated with the form and the combobox, but still haven't figured out what is the way of doing it. I have a table with products, tblProducts, some of them are Active while others are Inactive. The form shows all the products purchased by a customer, both Active and Inactive in a ComboBox, cbProducts. My client wants to view all...
2
12888
by: John Tyce | last post by:
When a button is clicked, a date is inserted or added into a combo box like this : ComboBox.Items.Add(string) or ComboBox.Items.Insert(0,string); Either way, the new string does not show up in the ComboBox. I get no errors or problems, it just will not work. At load time I am retrieving dates from an Oracle database and adding them to the ComboBox with out any problems. However, once the application is up and running I cannot add to the...
2
4334
by: pei_world | last post by:
I want to implement a key hit with enter to dropdown a combobox that is in the datagrid. in this case I need to override its original behaviours. I found some codes from the web. Does anyone know how to use this code? please help! http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_20862953.html
0
407
by: dbuchanan | last post by:
ComboBox databindng Problem == How the ComboBox is setup and used: My comboBox is populated by a lookup table. The ValueMember is the lookup table's Id and the DisplayMember is the text from a corresponding field in the lookup table. In my data table we store the ID in what I will call the 'key' field. == Description of the desired operation:
5
3190
by: Peter M. | last post by:
I'm struggling with combobox databinding with something I consider a bug... I'm binding my combobox to an array of structs. The struct exposes two public properties, ID and Name, to be used as the value and displaymember properties. This works fine. My combobox contains the correct data. However I'm also binding my SelectedValue property to a column in a datatable. Here's where I'm lost. The combobox doesn't show the correct
1
2075
by: amber | last post by:
I'm having an issue with a combobox that is making no sense to me at all. I have a form with several comboboxes/textboxes. The values in these boxes are based on a datarowview, which is based on a listbox.selecteditem. When a different item is selected in the listbox, all the fields are repopulated with the correct data. I have 1 combobox which is acting weird.
5
1507
by: active | last post by:
I tried to use a datasource with a combobox and it didn't work completely so I build a small test that was much more straight forward then the app. The test was to see if the combobox dropdown list displayed the correct data. However, although the designer shows the combobox the combobox does not show at runtime. If you would be so kind as to cut the code below and paste it into a form
1
4254
by: Andrus | last post by:
I need to enter null value from combobox to business object property. My combobox datasource does not contain ValueMember with null value. So I tried to create combobox which stores null to bound object when text is deleted. However bound object contains old value in this case. To reproduce: 1. Run code
7
13531
by: JTC^..^ | last post by:
When i attempt to bind to the "Text" and "Value" property of a combobox on a windows form the value is reset when I leave the combobox. The comboboxes contain the correct Text and Values. I know this as the Value property binds correctly on it own. It is only when I bind the "Text" and "Value" that the issue occurs. The following sample code includes my custom classes and the Form Clode. I have several comboboxes and customer classes...
14
6561
by: Mark | last post by:
I have a table with a field that uses a combobox to populate values. The Lookup tab within table design mode is the following: Display Control Combo Box Row Source Type Table/Query Row Source SELECT .LastName, .FirstName, .EmployeeNumber FROM ; Bound Column 3 Column Count 3 Column Heads Yes Column Widths 1";1";1"
0
9632
marktang
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10071
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9925
tracyyun
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8958
agi2029
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7478
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6723
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5501
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2867
bsmnconsultancy
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.