Jan 20, 2004 #1 khansen97 Programmer Oct 14, 2003 60 US Does anybody have any code that I can use to put the results of a query in a variable in MS Access? I have an SQL statement that gives me a field. I want to get that field into a variable, but I am really struggling. Any help would be great. thanks
Does anybody have any code that I can use to put the results of a query in a variable in MS Access? I have an SQL statement that gives me a field. I want to get that field into a variable, but I am really struggling. Any help would be great. thanks
Jan 20, 2004 #2 RoyVidar Instructor Jun 16, 2000 6,606 NO If you have a field, then you should be able to do. [tt]MyVariable = rst!SomeField[/tt] - or - if more complex, show what you have and elaborate on what you want to do. Roy-Vidar Upvote 0 Downvote
If you have a field, then you should be able to do. [tt]MyVariable = rst!SomeField[/tt] - or - if more complex, show what you have and elaborate on what you want to do. Roy-Vidar
Jan 21, 2004 #3 MinusM MIS Dec 1, 2003 126 KW Do you want something similar to Select @Var = Field1 in SQL server? If you are sure the SQL query will return only one row MyVar=Dlookup("MyField","MyQuery","MyCondition" should do For more than one row returned the value returned is not defined. You will have to open a recordset and assign to a variable as Roy suggested Best of luck Upvote 0 Downvote
Do you want something similar to Select @Var = Field1 in SQL server? If you are sure the SQL query will return only one row MyVar=Dlookup("MyField","MyQuery","MyCondition" should do For more than one row returned the value returned is not defined. You will have to open a recordset and assign to a variable as Roy suggested Best of luck