Click to See Complete Forum and Search --> : Read into variable
damarious
Sep 12th, 2000, 09:59 AM
Access 2000
If I have a table with 4 columns, all are text, how would I get the data from the 4th column into a variable using the 1st column as a reference.
For example:
cnum, cname, addy, IPs
-----------------------
1234, bob, 321 st, 1.1.1.1
I need to get a variable to contain 1.1.1.1 if cnum=1234
I don't think it's too tough, I'm just stuck.
AKA
Sep 12th, 2000, 10:57 AM
Try this for example
Dim rst As Recordset, dbs As Database, strSQL As String
Set dbs = CurrentDb()
strSQL = "select IPs from T_Your_Table where cnum = '" & strCNum & "' ;"
Set rst = dbs.OpenRecordset(strSQL)
rst.MoveFirst
strIPs = rst![IPs]
rst.Close
Set dbs = Nothing
damarious
Sep 12th, 2000, 11:11 AM
Thanks for the code chunk, it seems to be what I'm after, but it's throwing a "Type Mismatch" error where marked below.
Dim rst As Recordset, dbs As Database, strSQL As String
Dim strIPS As String
Set dbs = CurrentDb()
strSQL = "select IP from MainData where cnum = '" & cnumadd & "' ;"
Set rst = dbs.OpenRecordset(strSQL) <- THROWS ERROR!
rst.MoveFirst
strIPS = rst![IPs]
rst.Close
Set dbs = Nothing
MsgBox strIPS
AKA
Sep 12th, 2000, 11:15 AM
It migth bee easier to understand why you get an error if you examine the strSQL variable. You can also post it here and I can check it right away at least for next 10 minutes.
damarious
Sep 12th, 2000, 11:22 AM
strSQL = "select IP from MainData where cnum = '123456';"
That's it. The 123456 is a text string, not a number.
AKA
Sep 13th, 2000, 12:15 AM
Is not the cnum column text ? You said that in your first post. If not remove the ' but I assume that you allready figured that out.
damarious
Sep 13th, 2000, 09:41 AM
F.Y.I.
Dim rst As Recordset
Dim dbs As Database
Dim strSQL1 As String
Dim strIP As String
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("SELECT ips FROM MainData WHERE (MainData.cnum = '123456');") 'DIES HERE!
rst.MoveFirst
strIPS = rst![ips]
rst.Close
Set dbs = Nothing
MsgBox strIPS
DOES NOT WORK, But after I commented out
Dim rst As Recordset
I works fine.... go figure.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.