SQL SELECT in an Event Procedure

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a procedure I am trying to write withing a "On Click" from a form
button. In this, I would like to select a value from a record in a table,
compare that value to a value that a user entered, then have a IF/THEN based
on the comparison.

Any suggestions?
 
Dim var As Variant

var = DLookUp("value", "table")

If var = Me!ControlName Then
' do something
Else
' do something else
End If

hth
 
Thanks Tina for responding so quickly... I have tried this, and I keep
getting an error that says "You have canceled the previous operation".
Here is my code:
----------start-------------------------
Private Sub open_main_menu_form_Click()
On Error GoTo Err_open_main_menu_form_Click

Dim stDocName As String
Dim stLinkCriteria As String
Dim stUserName As String
Dim inGroupId As Variant

stUserName = Me![user-name-box]
inGroupId = DLookup("[sysu-user-group]", "sys-users", "[sysu-user-name]
= " & stUserName)

If inGroupId = 1 Then
DoCmd.Close
stDocName = "main-menu-all"
DoCmd.OpenForm stDocName, , , stLinkCriteria
ElseIf inGroupId = 2 Then
DoCmd.Close
stDocName = "main-menu-user"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
DoCmd.Close
stDocName = "password-fail-error"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If

Exit_open_main_menu_form_Click:
Exit Sub

Err_open_main_menu_form_Click:
MsgBox Err.Description
Resume Exit_open_main_menu_form_Click

End Sub
--------------end------------------
 
first, since you know what data type the [sysu-user-group] field is, suggest
you change the inGroupId variable's data type to match.

second, since stUserName is a String data type, then presumably the
[sysu-user-name] is a Text data type, so you'll need to correct the syntax
in the DLookup() function, as

DLookup("[sysu-user-group]", "sys-users", "[sysu-user-name]
= '" & stUserName & "'")

third, since you never set the value of stLinkCriteria in the procedure,
there's no point in including it in the OpenForm method, so suggest you
remove it from there and from the variable declarations.

hth


Thanks Tina for responding so quickly... I have tried this, and I keep
getting an error that says "You have canceled the previous operation".
Here is my code:
----------start-------------------------
Private Sub open_main_menu_form_Click()
On Error GoTo Err_open_main_menu_form_Click

Dim stDocName As String
Dim stLinkCriteria As String
Dim stUserName As String
Dim inGroupId As Variant

stUserName = Me![user-name-box]
inGroupId = DLookup("[sysu-user-group]", "sys-users", "[sysu-user-name]
= " & stUserName)

If inGroupId = 1 Then
DoCmd.Close
stDocName = "main-menu-all"
DoCmd.OpenForm stDocName, , , stLinkCriteria
ElseIf inGroupId = 2 Then
DoCmd.Close
stDocName = "main-menu-user"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
DoCmd.Close
stDocName = "password-fail-error"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If

Exit_open_main_menu_form_Click:
Exit Sub

Err_open_main_menu_form_Click:
MsgBox Err.Description
Resume Exit_open_main_menu_form_Click

End Sub
--------------end------------------

tina said:
Dim var As Variant

var = DLookUp("value", "table")

If var = Me!ControlName Then
' do something
Else
' do something else
End If

hth
 
Tina...

You are a blessing... Thanks for all your help with this. It worked
perfect.

Navatin



tina said:
first, since you know what data type the [sysu-user-group] field is, suggest
you change the inGroupId variable's data type to match.

second, since stUserName is a String data type, then presumably the
[sysu-user-name] is a Text data type, so you'll need to correct the syntax
in the DLookup() function, as

DLookup("[sysu-user-group]", "sys-users", "[sysu-user-name]
= '" & stUserName & "'")

third, since you never set the value of stLinkCriteria in the procedure,
there's no point in including it in the OpenForm method, so suggest you
remove it from there and from the variable declarations.

hth


Thanks Tina for responding so quickly... I have tried this, and I keep
getting an error that says "You have canceled the previous operation".
Here is my code:
----------start-------------------------
Private Sub open_main_menu_form_Click()
On Error GoTo Err_open_main_menu_form_Click

Dim stDocName As String
Dim stLinkCriteria As String
Dim stUserName As String
Dim inGroupId As Variant

stUserName = Me![user-name-box]
inGroupId = DLookup("[sysu-user-group]", "sys-users", "[sysu-user-name]
= " & stUserName)

If inGroupId = 1 Then
DoCmd.Close
stDocName = "main-menu-all"
DoCmd.OpenForm stDocName, , , stLinkCriteria
ElseIf inGroupId = 2 Then
DoCmd.Close
stDocName = "main-menu-user"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
DoCmd.Close
stDocName = "password-fail-error"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If

Exit_open_main_menu_form_Click:
Exit Sub

Err_open_main_menu_form_Click:
MsgBox Err.Description
Resume Exit_open_main_menu_form_Click

End Sub
--------------end------------------

tina said:
Dim var As Variant

var = DLookUp("value", "table")

If var = Me!ControlName Then
' do something
Else
' do something else
End If

hth


<Navatin> wrote in message
I have a procedure I am trying to write withing a "On Click" from a form
button. In this, I would like to select a value from a record in a
table,
compare that value to a value that a user entered, then have a IF/THEN
based
on the comparison.

Any suggestions?
 
you're very welcome :)


Tina...

You are a blessing... Thanks for all your help with this. It worked
perfect.

Navatin



tina said:
first, since you know what data type the [sysu-user-group] field is, suggest
you change the inGroupId variable's data type to match.

second, since stUserName is a String data type, then presumably the
[sysu-user-name] is a Text data type, so you'll need to correct the syntax
in the DLookup() function, as

DLookup("[sysu-user-group]", "sys-users", "[sysu-user-name]
= '" & stUserName & "'")

third, since you never set the value of stLinkCriteria in the procedure,
there's no point in including it in the OpenForm method, so suggest you
remove it from there and from the variable declarations.

hth


Thanks Tina for responding so quickly... I have tried this, and I keep
getting an error that says "You have canceled the previous operation".
Here is my code:
----------start-------------------------
Private Sub open_main_menu_form_Click()
On Error GoTo Err_open_main_menu_form_Click

Dim stDocName As String
Dim stLinkCriteria As String
Dim stUserName As String
Dim inGroupId As Variant

stUserName = Me![user-name-box]
inGroupId = DLookup("[sysu-user-group]", "sys-users", "[sysu-user-name]
= " & stUserName)

If inGroupId = 1 Then
DoCmd.Close
stDocName = "main-menu-all"
DoCmd.OpenForm stDocName, , , stLinkCriteria
ElseIf inGroupId = 2 Then
DoCmd.Close
stDocName = "main-menu-user"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
DoCmd.Close
stDocName = "password-fail-error"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If

Exit_open_main_menu_form_Click:
Exit Sub

Err_open_main_menu_form_Click:
MsgBox Err.Description
Resume Exit_open_main_menu_form_Click

End Sub
--------------end------------------

:

Dim var As Variant

var = DLookUp("value", "table")

If var = Me!ControlName Then
' do something
Else
' do something else
End If

hth


<Navatin> wrote in message
I have a procedure I am trying to write withing a "On Click" from
a
form
button. In this, I would like to select a value from a record in a
table,
compare that value to a value that a user entered, then have a IF/THEN
based
on the comparison.

Any suggestions?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top