Reply
Recordset in vba + access
Old 03-04-2008, 12:53 PM Recordset in vba + access
Novice Talker

Posts: 5
Why my code doesnt work properly?
letīs see my example:

Dim USER As String
Dim pswd As String
Dim userfromfrm As String
Dim pswfromfrm As String
Dim stDocName As String
Dim QUERY As String

Option Compare Database
Private Sub botrunmacro_Click()
' On Error GoTo Err_botrunmacro_Click
' TOMNO LOS VALORES DE LOS OBJETOS DEL FORM
userfromfrm = Form_FrmRunMacro.user01.Value
pswfromfrm = Form_FrmRunMacro.psw01.Value

' TENGO QUE RECUPERAR LOS VALORES DE LA TABLA

USER = Form_FrmRunMacro.Usuario.Value
pswd = Form_FrmRunMacro.ClavedeAcceso.Value

ArgSQL = "SELECT Usuario, Clavedeacceso from TBLUSUARIOS where TBLUSUARIOS.Usuario=" & userfromfrm & " & TBLUSUARIOS.ClaveDeAcceso =" & pswfromfrm & ";"

Dim USUS01 As Variant
Dim CLAVE01 As Variant
Dim rst As Recordset
Set rst = CurrentDb.OpenRecordset(ArgSQL, adOpenKeyset, adLockOptimistic)

With rst

If (.RecordCount > 0) Then

'MACHEO LOS PERFILES
Select Case Usuario
Case "OPCODE "
stDocName = "MACROOPENOPCODE"
End
Case "OPVTAGRAL"
stDocName = "MACROOPENOPVTAGRAL"
End
Case "USUARIOBASE"
stDocName = "MACROOPENUSUARIOBASE"
End
Case "ADMINISTRADOR"
stDocName = "MACROOPENUSUARIOBASE"
End
Case ""
MsgBox ("Debe ingresar usuartio y clave validos")
End
Case " "
MsgBox ("Debe ingresar usuartio y clave validos")
End

End Select

'EJECUTO LA MACRO PARA ACCEDER AL FORM INDICADO
DoCmd.RunMacro stDocName

rst.MoveNext

Else
MsgBox "Oops! No records!"
End If
End With
rst.Close

Anybody please, help!!!
ludmila is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 03-04-2008, 02:56 PM Re: Recordset in vba + access
chrishirst's Avatar
Super Moderator

Posts: 11,872
Location: Blackpool. UK
knowing what it is doing or not doing would be a help.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 03-05-2008, 09:21 AM Re: Recordset in vba + access
Novice Talker

Posts: 5
I will write below the code which i have problems with, error that shows is some parameters are not define.


Dim USER As String
Dim pswd As String
Dim userfromfrm As String
Dim pswfromfrm As String
Dim stDocName As String
Dim ArgSQL As String
Option Compare Database
Private Sub botrunmacro_Click()
' On Error GoTo Err_botrunmacro_Click

' TOMNO LOS VALORES DE LOS OBJETOS DEL FORM
userfromfrm = Form_FrmRunMacro.user01.Value
pswfromfrm = Form_FrmRunMacro.psw01.Value

' TENGO QUE RECUPERAR LOS VALORES DE LA TABLA

USER = Form_FrmRunMacro.Usuario.Value
pswd = Form_FrmRunMacro.ClavedeAcceso.Value


ArgSQL = "SELECT Usuario, Clavedeacceso from TBLUSUARIOS where TBLUSUARIOS.Usuario=" & userfromfrm & " & TBLUSUARIOS.ClaveDeAcceso =" & pswfromfrm & ";"

Dim con As New ADODB.Connection

Dim USUS01 As ADODB.Field

Set con = Application.CurrentProject.Connection
Set rs = CreateObject("ADODB.RecordSet")

rs.Open ArgSQL, con, adOpenForwardOnly, adLockReadOnly, adCmdText

Do Until rs.EOF
USUS01 = rs.Fields("USUARIO").Value
For Each USUS01 In rs.Fields
Select Case USUS01
Case "OPCODE "
stDocName = "MACROOPENOPCODE"
End
Case "OPVTAGRAL"
stDocName = "MACROOPENOPVTAGRAL"
End
Case "USUARIOBASE"
stDocName = "MACROOPENUSUARIOBASE"
End
Case "ADMINISTRADOR"
stDocName = "MACROOPENUSUARIOBASE"
End
Case ""
MsgBox ("Debe ingresar usuartio y clave validos")
End
Case " "
MsgBox ("Debe ingresar usuartio y clave validos")
End

End Select

DoCmd.RunMacro stDocName
Next
rs.MoveNext
Loop
rs.Close
con.Close
Set rs = Nothing
Set con = Nothing

End Sub

'------------
I will apreciate your answer.
ludmila is offline
Reply With Quote
View Public Profile
 
Old 03-06-2008, 03:41 PM Re: Recordset in vba + access
Learning Newbie's Avatar
Moderator

Latest Blog Post:
What Does This Look Like?
Posts: 4,727
Name: John Alexander
Debug.Print (ArgSQL)

Then take the results from the output console and paste those into a new query, try to run it, and take action as necessary.
__________________
4 ways to improve the lives of the "bottom billion"

"HEY YOU KIDS GET OFF MY LAWN!" -John McCain
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Recordset in vba + access
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.13292 seconds with 13 queries