Dear expert,
I got two forms.
form1: Combox form Form_rptStock (key field: serial number), with one command button.
form2: Entryform Entryform_stock, with a series of command buttons. I use this form to add new record or edit/delete a record. (it works perfect independently)
What I am trying to do is when I select a serial number from the dropdown and click the command button cmdEdit in the 1st form, I wish the 2nd form will open and then, run the procedures I choose from the 2nd form. My problem is that the active connection is still in the first form, so it wil not recogernise or run the code in the 2nd form. How could I change the active connection to the second form when it is opened?
I got some brief code as in the follwoing:
code 1: to open the second form
-
Dim stDocName As String
-
stDocName = "entryform_Stock"
-
DoCmd.OpenForm stDocName, , acNormal
-
cmdEdit_Click (----procedure in the 2nd form I wish to run)
-
Code 2: cmdEdit_click () (only part of the whole code)
-
Private Sub cmdEdit_Click()
-
On Error GoTo err
-
Dim cnn As ADODB.Connection
-
Dim rst2 As Recordset
-
Set rst2 = New ADODB.Recordset
-
Set cnn = CurrentProject.Connection
-
rst2.ActiveConnection = cnn
-
rst2.CursorType = adOpenKeyset
-
rst2.LockType = adLockOptimistic
-
Dim boolInTrans As Boolean
-
boolInTrans = False
-
cmdDelete.Enabled = False
-
cmdAdd.Enabled = False
-
-
If cmdEdit.Caption = "Edit" Then
-
' UnLocked
-
cnn.BeginTrans
-
boolInTrans = True
-
Dim key As String
-
key = InputBox("Enter Serial Number ")
-
-
-
rst2.ActiveConnection = CurrentProject.Connection
-
rst2.CursorType = adOpenStatic
-
rst2.LockType = adLockOptimistic
-
-
rst2.Open "select * from tblStock"
-
-
strSql = "Serial_Number=" & key
-
rst2.Find strSql
-
Any help is highly appreciated.
Jay