UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

> Using vba to get single value from a table with criteria and the    
 
   
oso
post Feb 3 2006, 07:26 AM
Post #1

UtterAccess Enthusiast
Posts: 88



I have a basequery named qryFghEkonomi and a global variable, dim dak as long and a module shown below.
I then use this code in a form, it all works fine until the moment when I want to save the value to the variable and then display it in a textbox. According to the msgbox the value of dak i 0
and when trying toi assign the textbox a value i get the message can not assign that objekt a value. The funny thing is if I pull up the question manually and run it with the form open after clicking the button ( so the qry is changed according to GetDAK() ) i get the correct value but it will not be saved into the variable.

Option Compare Database
Option Explicit

Public Function GetDAK() As Integer

Dim qry As QueryDef
Dim DB As Database
Dim sSql As String

Set DB = CurrentDb()
Set qry = DB.QueryDefs("qryFghEkonomi")

qry.SQL = "SELECT intDAK FROM [tblFghEkonomi] " & _
"WHERE [intFastighetsnummer]=[forms].[frmNyAlgh].[intFastighetsnummer];"
dak = DMax("[intDak]", "qryFghEkonomi")

Set qry = Nothing
End Function

In the form:

Private Sub cmdGetDAK_Click()
On Error GoTo Err_cmdGetDAK_Click


Call GetDAK
Me.txtDAK = dak

MsgBox dak

Exit_cmdGetDAK_Click:
Exit Sub

Err_cmdGetDAK_Click:
MsgBox Err.Description
Resume Exit_cmdGetDAK_Click

End Sub
Go to the top of the page
 
+

Posts in this topic


Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 24th May 2013 - 09:25 AM