Orange and Micron:
Thanks for you replies. I only expect 1 record as this is part of the build process for a new server. You are correct about the record set stuff, in my frustration I have been grasping at straws, so to speak.
I do use indentations in all my codeing, I don't know why it didn't show up when I copied it to my post?
I tried the DLookup function but it returns "????????" instead of the number expected. That number should be "{01ACAA27-E7FE-E555-72E5-B3D35B92776A}". Here is the code I am using: LSID = DLookup("[LogicalServerID]", "LogicalServer", "[Name] = '" & SName & "'"). I know that SName contains the correct server name. Also attached is the complete Sub code. I took this line directly from an example on "AccessWorld.com". Is the syntax correct?
Code:
Private Sub cmdOK_Click()
Dim LSID As Variant
Dim SVID As Variant
Dim sqlQry As String, SName As String
Dim mydb As Database, myrs As DAO.Recordset
''' Get the LogicalServerID for the Server named on the "Details" tab
SName = Forms!frmLogicalServers!txtServerNm
LSID = DLookup("[LogicalServerID]", "LogicalServer", "[Name] = '" & SName & "'")
SVID = Me.lstAssocServices.Column(0)
sqlQry = "INSERT INTO ServiceLogicalServer ([ServiceID], [LogicalServerID]" _
& " VALUES (SVID, LSID);"
DoCmd.RunSQL sqlQry
sqlQry = "INSERT INTO ServertoService ([Name], [Description],[ServiceID], [LogicalServerID]" _
& " VALUES ([forms.frmLogicalServers.txtServerNm], [Me.lstAssocServices.column(1)], SVID, LSID);"
DoCmd.RunSQL sqlQry
End Sub
Code tags added.
Shylock: Re Code tags: Highlight your code, then click the hash (#)--this puts "code" tags around the vba. (orange)