473,657 Members | 2,300 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Recordset Question

i am opening a recordset in my VB code and populating a combo box with
the data from one of the fields in my recordset. I want to set it up so
that, when a user selects one of the values from the combo box, the
text boxes on the form will be populated with the associated data. This
is driving me insane! I've researched almost all day on this, and can't
seem to find an answer. Any help would would be HUGELY appreciated as
this is part of a project for the pres of our company......

Public dbMyDB As DAO.Database
Public rsMyRS As DAO.Recordset
Public MySQL1 As String

Public Sub Form_Load()

MySQL1 = "SELECT DISTINCT (calc.Employee_ Number) AS empnum, " & _
"sum(calc.total ) AS totalearned,
sum(redpts.poin ts_redeemed) AS used, " & _
"calc.Last_ Name AS lname, calc.First_Name AS fname " & _
"FROM Calculation AS calc LEFT JOIN Redeemed_Points AS
redpts " & _
"ON calc.Employee_N umber=redpts.Em ployee_Number " & _
"GROUP BY calc.Employee_N umber, calc.Last_Name,
calc.First_Name "
Set dbMyDB = CurrentDb()
Set rsMyRS = dbMyDB.OpenReco rdset(MySQL1, dbOpenDynaset)

If Not rsMyRS.EOF Then rsMyRS.MoveFirs t
Do While Not rsMyRS.EOF
cmbEmpNum.AddIt em rsMyRS!empnum
' cmbEmpNum.ItemD ata(cmbEmpNum.N ewIndex) = rsMyRS!empnum 'This
line throws an error
rsMyRS.MoveNext
Loop

End Sub

Private Sub cmbEmpNum_Click ()

rsMyRS.FindFirs t "empnum= '" & Str(cmbEmpNum.V alue) & "'"
'These will populate, but only with the data from the 1st record
regardless of the cmbEmpNum value
txtLastName = rsMyRS!lname
txtFirstName = rsMyRS!fname

End Sub

Sep 13 '06 #1
2 1423
Airman,
Have one query as the rowsourse for your combobox.
Have another query which is the recordsource of your form an which
takes the value of the combo box as one of the criteria.
Then use the afterupdate property of th combo box to requery the form.

ai*******@hotma il.com wrote:
i am opening a recordset in my VB code and populating a combo box with
the data from one of the fields in my recordset. I want to set it up so
that, when a user selects one of the values from the combo box, the
text boxes on the form will be populated with the associated data. This
is driving me insane! I've researched almost all day on this, and can't
seem to find an answer. Any help would would be HUGELY appreciated as
this is part of a project for the pres of our company......

Public dbMyDB As DAO.Database
Public rsMyRS As DAO.Recordset
Public MySQL1 As String

Public Sub Form_Load()

MySQL1 = "SELECT DISTINCT (calc.Employee_ Number) AS empnum, " & _
"sum(calc.total ) AS totalearned,
sum(redpts.poin ts_redeemed) AS used, " & _
"calc.Last_ Name AS lname, calc.First_Name AS fname " & _
"FROM Calculation AS calc LEFT JOIN Redeemed_Points AS
redpts " & _
"ON calc.Employee_N umber=redpts.Em ployee_Number " & _
"GROUP BY calc.Employee_N umber, calc.Last_Name,
calc.First_Name "
Set dbMyDB = CurrentDb()
Set rsMyRS = dbMyDB.OpenReco rdset(MySQL1, dbOpenDynaset)

If Not rsMyRS.EOF Then rsMyRS.MoveFirs t
Do While Not rsMyRS.EOF
cmbEmpNum.AddIt em rsMyRS!empnum
' cmbEmpNum.ItemD ata(cmbEmpNum.N ewIndex) = rsMyRS!empnum 'This
line throws an error
rsMyRS.MoveNext
Loop

End Sub

Private Sub cmbEmpNum_Click ()

rsMyRS.FindFirs t "empnum= '" & Str(cmbEmpNum.V alue) & "'"
'These will populate, but only with the data from the 1st record
regardless of the cmbEmpNum value
txtLastName = rsMyRS!lname
txtFirstName = rsMyRS!fname

End Sub
Sep 13 '06 #2
To load your combobox you can do this:

Private sub Form_Load()
Combo0.RowSourc e = "Select fld1, fld2, fld3 From tbl1"
End Sub

Then in the Click event of the combobox you can populate what ever you
need:

Private Sub Combo0.Click()
txt0 = Combo0.Column(0 )
End Sub

Note: in the rowsource sql I load data from 3 columns of tbl1. In
order for all 3 columns to show up in the combobox at run time - go to
the property sheet of the combobox in design view and type 3 in the
Column Count property box (3 in my exmaple - could be less, more). The
default is 1 column - for which you don't need to enter anything in the
Column Count property. And to extend the populating idea, you could
populate more controls from one row of the combobox if you have more
than one column in the rowsource:

Private Sub Combo0_Click()
txt0 = Combo0.Column(0 )
txt1 = Combo0.Column(1 )
txt2 = Combo0.Column(2 )
End Sub

HTH
Rich

*** Sent via Developersdex http://www.developersdex.com ***
Sep 13 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1782
by: Rob Meade | last post by:
Lo all, I have a local recordset which is not linked to a database. Some of the fields in this recordset contain html tags. I have a function which is called when I'm calculating my relevance for search results which gets the row from the recordset, strips out the html tags, then does its magic to produce the 'relevance' for that row.
4
3086
by: Tom | last post by:
I want to open a recordset object on an .asp page. When I open the recordset I would like to use a stored procedure that expects a parameter to be passed for the stored procedure. I will then use the recordset to loop thru the recordset, update values from the recordset and then update the database by passing parmeters to another stored procedure. I would like to use the recordset object but can it be used to pass a parameter to a stored...
4
1506
by: Joseph | last post by:
Hi all- I am a former VB6 programmer and new at C# and I have a question dealing with converting some code from VB6 to C#. The code is below and essentially, what it does is gets data from a SQL Server database and parses some of the data and puts the parsed data into a text field. I omitted a some of the code and left the data parsing part of it, which is what my question is about. Exactly what the code below does is gets data from SQL...
7
2275
by: tdr | last post by:
I need to compare table 1 to table 2 and if the row/recordset in table 1 is different from table 2, write the entire row/recordset from table 1 to table 3. I can read an entire row/recordset from table 1 into a recordset using the following strSQL_in = "select * from table1" ( and i can refer to the columns as needed)
4
2708
by: =?Utf-8?B?R1ROMTcwNzc3?= | last post by:
Hi Guys, thanks for your help yesterday, I've got one more question, then I think I'm done for now,... Is it possible to insert recordset data in a javascript, for instance I have a javascript code that calculates the total price, depending on number of units, currently what the code does is set the price like so - if qty 1 then £99+VAT if qty equall to or greater than 2 and equall to or less than 9 then price =
0
8323
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8838
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8739
jinu1996
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8513
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
8613
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...
1
6176
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
4173
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
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1732
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.