I am checking the order qty at order entry to make sure the orders are in full case packs (12) this is stored in the IMITMIDX user field 4.
I got this to work using "ersrecset" but would like to use ADO.
I have read some previous posts from VBAJock and tried to get it to work.
Thanks
Public Macola As New Connection
Function OpenMacolaConnection()
On Error GoTo OpenMacolaConnection_err
'initialize the object
Set Macola = Nothing
'this value may vary according to the speed of your system
Macola.ConnectionTimeout = 120
Macola.Open "Provider=MSDASQL;DSN=Macola"
OpenMacolaConnection = True
Exit Function
'***********************
OpenMacolaConnection_err:
'***********************
MsgBox Str$(Err) + Error$
OpenMacolaConnection = False
End Function
Private Sub Qty1_GotFocus()
'Call the function in your code by using this line:
Call OpenMacolaConnection
'Subsequent code can then use the open connection to do stuff. In the following example I use it to create a copy of the ARTYPFIL in an Access database:
Dim Ordqty As String
Dim Item As String
Dim CPstmt As String
Dim cpvalue As Double
Dim macrs As Recordset
Ordqty = macForm.Qty.Text
Item = macForm.ItemNo.Text
On Error GoTo PopArTypeFile_Err
Set macrs = New ADODB.Recordset
CPstmt = "SELECT IMITMIDX.USER_FIELD_4 "
CPstmt = CPstmt & "FROM IMITMIDX WHERE IMITMIDX.Item_no = '" & Item & "'"
macrs.Open CPstmt ', Macola, adOpenForwardOnly, adLockReadOnly, adCmdText
If IsNumeric(("IMITMIDX.USER_Field_4") Then
cpvalue = ("IMITMIDX.USER_FIELD_4"
MsgBox "" & cpvalue
If Ordqty Mod cpvalue = 0 Then
Else
Dim Msg, Style, Title, Help, Ctxt, Response, MyString
Msg = "Order Qty not a full case, Would you like to fix qty?, Case Pack= " & cpvalue
Style = vbYesNo + vbDefaultButton1 ' Define buttons.
Title = "Casepack Verification" ' Define title.
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbYes Then ' User chose Yes.
macForm.Qty.SetFocus
Set macImitmidx = Nothing
PopArTypeFile_Err:
MsgBox Str$(Err) + " " + Error$
PopARTypeFile = False
End If
End If
End If
End Sub
I got this to work using "ersrecset" but would like to use ADO.
I have read some previous posts from VBAJock and tried to get it to work.
Thanks
Public Macola As New Connection
Function OpenMacolaConnection()
On Error GoTo OpenMacolaConnection_err
'initialize the object
Set Macola = Nothing
'this value may vary according to the speed of your system
Macola.ConnectionTimeout = 120
Macola.Open "Provider=MSDASQL;DSN=Macola"
OpenMacolaConnection = True
Exit Function
'***********************
OpenMacolaConnection_err:
'***********************
MsgBox Str$(Err) + Error$
OpenMacolaConnection = False
End Function
Private Sub Qty1_GotFocus()
'Call the function in your code by using this line:
Call OpenMacolaConnection
'Subsequent code can then use the open connection to do stuff. In the following example I use it to create a copy of the ARTYPFIL in an Access database:
Dim Ordqty As String
Dim Item As String
Dim CPstmt As String
Dim cpvalue As Double
Dim macrs As Recordset
Ordqty = macForm.Qty.Text
Item = macForm.ItemNo.Text
On Error GoTo PopArTypeFile_Err
Set macrs = New ADODB.Recordset
CPstmt = "SELECT IMITMIDX.USER_FIELD_4 "
CPstmt = CPstmt & "FROM IMITMIDX WHERE IMITMIDX.Item_no = '" & Item & "'"
macrs.Open CPstmt ', Macola, adOpenForwardOnly, adLockReadOnly, adCmdText
If IsNumeric(("IMITMIDX.USER_Field_4") Then
cpvalue = ("IMITMIDX.USER_FIELD_4"
MsgBox "" & cpvalue
If Ordqty Mod cpvalue = 0 Then
Else
Dim Msg, Style, Title, Help, Ctxt, Response, MyString
Msg = "Order Qty not a full case, Would you like to fix qty?, Case Pack= " & cpvalue
Style = vbYesNo + vbDefaultButton1 ' Define buttons.
Title = "Casepack Verification" ' Define title.
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbYes Then ' User chose Yes.
macForm.Qty.SetFocus
Set macImitmidx = Nothing
PopArTypeFile_Err:
MsgBox Str$(Err) + " " + Error$
PopARTypeFile = False
End If
End If
End If
End Sub