|
-
Oct 26th, 2004, 01:10 PM
#1
Thread Starter
Hyperactive Member
Assigning value from SQL statement to a variable
Can anyone help me assign the value of an SQL statement to a variable...
Here is what I have so far:
Code:
Dim strID As Recordset
Set strID = New Recordset
strID.Source = "SELECT tblLIST_CS_EMP.ID " & _
"FROM tblLIST_CS_EMP WHERE tblLIST_CS_EMP.Full_Name = " & Me.cboName & ""
MsgBox strID.Source
The current output is the whole SQL statement with an equals sign and the coreect ID.
So, I am stuck on how to pull just the ID out of the recordset.
-
Oct 26th, 2004, 04:27 PM
#2
Actually this should be a question for the Databases forum,
but if I understand your question correctly you want to retrieve
an id field based upon an entered id value in the combo box?
VB Code:
Dim strID As Recordset
Set strID = New Recordset
strID.Source = "SELECT tblLIST_CS_EMP.ID " & _
"FROM tblLIST_CS_EMP WHERE tblLIST_CS_EMP.ID = " & Me.cboID.Text
MsgBox strID.Source
Assuming that ID field is a numeric and this is for Access or SQL.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Oct 26th, 2004, 06:31 PM
#3
Thread Starter
Hyperactive Member
Sorry...
...didn't notice a database section.
Actually, I want to retrieve and ID field based upon an entered Full_Name in a combo box.
Basically I have 2 combo boxes, one cboName, and one cboID.
The user can use either one to select the person they are looking for.
However, when the full name is chosen, I want the cboID to show the appropriate ID, and vice versa.
I tried your code, with the adjustment:
Code:
Dim strID As Recordset
Set strID = New Recordset
strID.Source = "SELECT tblLIST_CS_EMP.L_ID " & _
"FROM tblLIST_CS_EMP WHERE tblLIST_CS_EMP.Full_Name = " & Me.cboName.Text
And the msgbox is just displaying the SQL code with value that is in the cboName.Text.
I am using an Access database and putting this code within a form in that access database,
-
Oct 26th, 2004, 08:31 PM
#4
Use the fields collection of the recordset. Modify your sql statement
for which cbo the user is using. Then populate the other cbo like
this...
VB Code:
Option Compare Database
Private Sub cboName_Click()
Dim strID As Recordset
Set strID = New Recordset
strID.Source = "SELECT tblLIST_CS_EMP.L_ID " & _
"FROM tblLIST_CS_EMP WHERE tblLIST_CS_EMP.Full_Name = " & Me.cboName.Text
strID.OpenRecordset dbOpenDynamic, dbReadOnly
Me.cboL_ID.AddItem strID.Fields("L_ID").Value
End Sub
Private Sub cboID_Click()
Dim strID As Recordset
Set strID = New Recordset
strID.Source = "SELECT tblLIST_CS_EMP.Full_Name " & _
"FROM tblLIST_CS_EMP WHERE tblLIST_CS_EMP.L_ID = " & Me.cboID.Text
strID.OpenRecordset dbOpenDynamic, dbReadOnly
Me.cboName.AddItem strID.Fields("Full_Name").Value
End Sub
You will need to add error trapping and a little more logic to
complete your procedures.
HTH
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Oct 27th, 2004, 09:29 AM
#5
Thread Starter
Hyperactive Member
hmmm....
...Getting this error:
"Method or datamember not found" on this code:
.OpenRecordset
on this line:
strID.OpenRecordset dbOpenDynamic, dbReadOnly
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|