|
-
Sep 12th, 2000, 09:59 AM
#1
Thread Starter
Member
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.
-
Sep 12th, 2000, 10:57 AM
#2
Lively Member
Try this for example
Code:
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
Yesterday, all my troubles seemed so far away...
Help, I need somebody, Help...
Now MCSD and still locking for intresting job in the south parts of Stockholm, Sweden.
-
Sep 12th, 2000, 11:11 AM
#3
Thread Starter
Member
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
-
Sep 12th, 2000, 11:15 AM
#4
Lively Member
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.
Yesterday, all my troubles seemed so far away...
Help, I need somebody, Help...
Now MCSD and still locking for intresting job in the south parts of Stockholm, Sweden.
-
Sep 12th, 2000, 11:22 AM
#5
Thread Starter
Member
strSQL = "select IP from MainData where cnum = '123456';"
That's it. The 123456 is a text string, not a number.
-
Sep 13th, 2000, 12:15 AM
#6
Lively Member
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.
Yesterday, all my troubles seemed so far away...
Help, I need somebody, Help...
Now MCSD and still locking for intresting job in the south parts of Stockholm, Sweden.
-
Sep 13th, 2000, 09:41 AM
#7
Thread Starter
Member
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.
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
|