alpinhasov
Programmer
Hello, I would like to know how to run a query in vba. In the code below I tried to create a query and run it but it just showed me the query in the message box.
Also if I have a form keep the values when I press a button which will take me to another form. The values which were in the first form will be then put automatically to the other form. Obviously the fields that will be copied are the same on the
two forms.
Private Sub insertData_Click()
Dim myconnection As ADODB.Connection
Set myconnection = CurrentProject.Connection
Dim myrecordset As New ADODB.Recordset
myrecordset.ActiveConnection = myconnection
myrecordset.Open "studdemo", , adOpenStatic, adLockOptimistic
Dim result As String
Dim minhag As String
minhag = "SELECT STDLASTN FROM STUDDEMO"
'DoCmd.RunSQL minhag
result = Me![txtMy] & " " & Me![txtMc]
MsgBox ("You have entered in My and Mc information " & result)
MsgBox ("The full name is " & Me![fullname])
MsgBox ("The students cuastom is " & minhag)
Dim myQuery As String
'myQuery = "Insert into MINYAN (date, fullname, My, Mc ) Values Me![date], Me![fullname], Me![txtMy], Me![txtMc]"
'DoCmd.RunSQL myQuery
End Sub
Also if I have a form keep the values when I press a button which will take me to another form. The values which were in the first form will be then put automatically to the other form. Obviously the fields that will be copied are the same on the
two forms.
Private Sub insertData_Click()
Dim myconnection As ADODB.Connection
Set myconnection = CurrentProject.Connection
Dim myrecordset As New ADODB.Recordset
myrecordset.ActiveConnection = myconnection
myrecordset.Open "studdemo", , adOpenStatic, adLockOptimistic
Dim result As String
Dim minhag As String
minhag = "SELECT STDLASTN FROM STUDDEMO"
'DoCmd.RunSQL minhag
result = Me![txtMy] & " " & Me![txtMc]
MsgBox ("You have entered in My and Mc information " & result)
MsgBox ("The full name is " & Me![fullname])
MsgBox ("The students cuastom is " & minhag)
Dim myQuery As String
'myQuery = "Insert into MINYAN (date, fullname, My, Mc ) Values Me![date], Me![fullname], Me![txtMy], Me![txtMc]"
'DoCmd.RunSQL myQuery
End Sub