For Loop Being Skipped Over - excel

I have not been able to figure out why the For Loop block (with two for loops) is being skipped over by the code. I know it's being skipped bc a message box is being tripped further down in the code. Any thoughts?
Dim OL As Outlook.Application
Dim myitem As Outlook.MailItem
Dim wb As Workbook
Dim ws As Worksheet
Dim PicPath As String
Dim x, y As Integer
Dim Name As Name
Dim cell, rng1 As Range
Set wb = ActiveWorkbook
Set ws = wb.Sheets("Sheet1")
wb.Sheets("Sheet1").Activate
'Request type check
If (Sheet1.NewResource.Value = False) And (Sheet1.Modification.Value = False) Then
MsgBox "Please select a Request Type of your request and complete the other mandatory fields"
GoTo cont
End If
'checking New Resource Entry mandatory fields
If Sheet1.NewResource.Value = True Then
If (Sheet1.NewPOnobx.Value = False) And (Sheet1.NewPOyesbx.Value = False) Then
MsgBox "Please fill the missing mandatory fields"
GoTo cont
End If
If (Sheet1.POyesbx.Value = False) And (Sheet1.POnobx.Value = False) Then
MsgBox "Please fill the missing mandatory fields"
GoTo cont
End If
If (Sheet1.POnobx.Value = True) And (Sheet1.SOWtxt.Value = "") Then
MsgBox "Please select a copy of the Signed Agreement"
GoTo cont
End If
For Each Name In ActiveWorkbook.Names 'each named range in gateway fields
If (Name = "C_LN") Or (Name = "C_FN") Or (Name = "C_SD") Or (Name = "C_ED") Or (Name = "C_O") Or (Name = "C_D") Or (Name = "C_OF") Or (Name = "C_C") Or (Name = "C_M") Or _
(Name = "C_R") Or (Name = "C_PT") Or (Name = "C_V") Or (Name = "C_SAR") Or (Name = "C_BAR") Or (Name = "C_SR") Or (Name = "C_SS") Or (Name = "C_PO") Then 'all gateway field names
x = 0
For Each cell In Name 'cell in the named range
If cell.Value = "" Then 'looking for blank mandatory fields
If (cell.Name = "LN_Cmt") Or (cell.Name = "FN_Cmt") Or (cell.Name = "SD_Cmt") Or (cell.Name = "ED_Cmt") Or (cell.Name = "O_Cmt") Or _
(cell.Name = "D_Cmt") Or (cell.Name = "OF_Cmt") Or (cell.Name = "C_Cmt") Or (cell.Name = "M_Cmt") Or (cell.Name = "R_Cmt") Or _
(cell.Name = "PT_Cmt") Or (cell.Name = "V_Cmt") Or (cell.Name = "SAR_Cmt") Or (cell.Name = "BAR_Cmt") Or (cell.Name = "SR_Cmt") Or _
(cell.Name = "SS_Cmt") Or (cell.Name = "PO_Cmt") Then
GoTo skip1
Else
x = x + 1 '+1 for a blank mandatory field
End If
End If
skip1:
Next cell
If x > 0 Then 'flag the missing info
MsgBox "Please fill the missing mandatory fields"
GoTo cont
End If
End If
Next Name
End If

For me, the Name in the for loop gives something like =Sheet1!$G$2:$G$5 ... this doesn't match your C_R or whatever. I need to use Name.Name to get that. And then to get the range of cells for the name, I need to use Name.RefersToRange.
Also, to make your If list easier to manage, you could use Select Case instead:
Select Case Name.Name
Case "C_LN", "C_FN", "C_SD", "C_ED", "C_O", "C_D", "C_OF", "C_C", "C_M", "C_R", "C_PT", "C_V", "C_SAR", "C_BAR", "C_SR", "C_SS", "C_PO"
For Each cell In Name.RefersToRange
Debug.Print cell.Address
Next cell
Case Else
Debug.Print "Other Name"
End Select

Don't use name it is a reserved word (you can rename files with Name File1 as File2).
Change the variable name to MyName or something similar then if you continue to experience the issue, put a stop on the code and evaluate the loop manually in the debug wind (CTRL-G) by typing ?activeworkbook.Names.Count and pressing enter (don't forget the ?) and see if you have a number above zero.

Related

How to get PO with each SIZE/EAN breakdown on ITEM level?

QUESTION
I'm using VBA for retrieving data from SAP via BAPI. What RFC should I use, and how, to retrieve PO details at the "each SIZE for each ITEM" level.
EXAMPLE
In this screenshot you see that the PO includes 3 ITEMs. Each of these ITEMs includes several SIZEs/EANs. And for each of the SIZEs/EANs, the specific QUANTITIES are indicated
I want to retrieve this data into Excel. So I create all the needed objects for working with SAP, connect to BAPI_PO_GETITEMS, fill in PURCHASEORDER-parameter, indicate the table PO_ITEMS:
Option Explicit
Public Functions As SAPFunctionsOCX.SAPFunctions
Private LogonControl As SAPLogonCtrl.SAPLogonControl
Private objConnection As SAPLogonCtrl.Connection
Dim Func As SAPFunctionsOCX.Function
Public eNUMBER_OF_ENTRIES As SAPFunctionsOCX.Parameter
Public tENTRIES As SAPTableFactoryCtrl.Table
Public TableFactory As SAPTableFactory
Sub BAPI_PO_GETDETAIL()
Dim i As Integer, j As Integer
Dim retcd As Boolean
Dim SilentLogon As Boolean
Set LogonControl = CreateObject("SAP.LogonControl.1")
Set Functions = CreateObject("SAP.Functions")
Set TableFactory = CreateObject("SAP.TableFactory.1")
Set objConnection = LogonControl.NewConnection
SilentLogon = True
'Use the below block to hardcode system connection and connect automatically
objConnection.Client = ""
objConnection.ApplicationServer = ""
objConnection.Language = ""
objConnection.User = ""
objConnection.Password = ""
objConnection.System = ""
objConnection.SystemNumber = ""
'Logging into SAP
If objConnection.Logon(0, SilentLogon) Then
'Logon was successful
MsgBox "Logged on!"
'Create an object to call the RFC FM
Functions.Connection = objConnection
'Actual FM is added here
Set Func = Functions.Add("BAPI_PO_GETITEMS")
'Populate the importing parameters
Func.Exports("PURCHASEORDER").Value = "2845158864"
'Indicate the TABLE needed
Set tENTRIES = Func.Tables("PO_ITEMS")
'Call FM
Func.Call
'Dump onto the worksheet
For i = 1 To tENTRIES.ColumnCount 'cells(R, C)
cells(1, i).Value = tENTRIES.ColumnName(i)
Next i
For i = 1 To tENTRIES.RowCount
For j = 1 To tENTRIES.ColumnCount
cells(i + 1, j).Value = tENTRIES.Value(i, j)
Next j
Next i
Else
MsgBox "Not Logged on"
End If
End Sub
and get only 3 rows - for each of the 3 ITEMS, without the breakdown by SIZE/EAN:
How to retrieve the breakdown by SIZE/EAN, like on this screenshot:

For each code not making check box value true

I am trying to create code that runs through a list of user ID's (B Numbers) and then when it finds the corresponding ID it checks to see if there's an X in the column directly next to it for a certain subject named SBB005 See image. If there is an X, I want the check box value to be true. The for each loop ends when it reaches a blank cell.
I have declared the 'RowYear2' and 'Year2CourseRange' ranges as public variables, and when running the code, nothing happens and the check box remains unticked! Any idea why the checkbox isn't being ticked as expected?
I am planning on setting up multiple checkboxes once this is working for all the subjects in each column:
See image
Hoping that someone can help me to get this working or may even introduce an easier way to do so for another 20 checkboxes!
Many thanks :)
Private Sub UserForm_Initialize()
Set Year2CourseRange = Sheets("Year2").Range("A:A")
For Each RowYear2 In Year2CourseRange.Cells
If RowYear2.Value = BNumberTxt Then
If RowYear2.Offset(0, 1) = "x" Then
Me.CHKSBB005.value = True
Else
Me.CHKSBB005.value = False
End If
ElseIf IsEmpty(RowYear2) Then
Exit For
End If
Next RowYear2
LoggedInTxt = Row.Offset(0, -3)
BNumberTxt = Row.Offset(0, -7)
CourseTxt = Row.Offset(0, -1)
CourseNumTxt = Row.Offset(0, -2)
End Sub
Private Sub EnterBtn_Click()
Dim LIMatch As Boolean
Dim Win As Boolean
Email = Me.EmailTxt
Password = Me.PasswordTxt
Set UserRange = Sheets("StudentInformation").Range("H:H")
For Each Row In UserRange.Cells
If Me.EmailTxt = "" And Me.PasswordTxt = "" Then
MsgBox ("Please enter an email and password")
LIMatch = False
Win = True
Exit For
ElseIf Me.EmailTxt = "" Then
MsgBox ("Please enter an email address")
LIMatch = False
Win = True
Exit For
ElseIf Me.PasswordTxt = "" Then
MsgBox ("Please enter a password")
LIMatch = False
Win = True
Exit For
Else
If UCase(Row.Value) = UCase(Email) Then
If UCase(Row.Offset(0, -6)) = UCase(Password) Then
MsgBox "Welcome"
LIMatch = True
Win = True
Attempts = 0
Exit For
ElseIf IsEmpty(Row) Then
Exit For
Win = False
Else
LIMatch = False
Win = False
Exit For
End If
Else
LIMatch = False
Win = False
End If
End If
Next Row
If LIMatch = True And Win = True Then
Unload Me
NewForm.Show
ElseIf LIMatch = False And Win = False Then
MsgBox ("Incorrect login")
Attempts = Attempts + 1
Else
End If
If Attempts >= 3 Then
MsgBox ("You have entered the incorrect login 3 times")
Unload Me
End If
End Sub
Once you fix your problem with the Row global, you can do something like this:
Private Sub UserForm_Initialize()
Dim shtData As Worksheet
Dim Year2CourseRange As Range, HeaderRange As Range, m, c As Range
Set shtData = ThisWorkbook.Sheets("Year2")
With shtData
Set Year2CourseRange = .Range("A:A")
Set HeaderRange = .Range(.Range("B2"), .Cells(2, 500).End(xlToLeft))
End With
'you'll need to fix this part....
BNumberTxt = Row.Offset(0, -7)
'etc
'find a matching row: Match() is a good approach here
m = Application.Match(BNumberTxt, Year2CourseRange, 0)
'loop over all the column headers
For Each c In HeaderRange.Cells
'Assumes all checkboxes are named "CHK[ColumnHeaderHere]"
With Me.Controls("CHK" & c.Value)
If IsError(m) Then
.Value = False 'clear all if no match
Else
.Value = (UCase(shtData.Cells(m, c.Column)) = "X") 'set if "x"
End If
End With
End If
End Sub
Ranges and Ranges
This is your code squashed a little bit and below is your data:
Private Sub UserForm_Initialize()
Set Year2CourseRange = Sheets("Year2").Range("A:A")
For Each RowYear2 In Year2CourseRange.Cells
If RowYear2.Value = BNumberTxt Then
If RowYear2.Offset(0, 1) = "x" Then
Me.CHKSBB005.value = True
Else: Me.CHKSBB005.value = False: End If
ElseIf IsEmpty(RowYear2) Then
Exit For: End If: Next RowYear2
LoggedInTxt = Row.Offset(0, -3): BNumberTxt = Row.Offset(0, -7)
CourseTxt = Row.Offset(0, -1): CourseNumTxt = Row.Offset(0, -2): End Sub
Take a look for a while, you might see the error yourself.
The CheckBox Tick Mystery
When you write Range("A:A") that refers to the whole column including Range("A1") which appears to be EMPTY. The code never even enters the If RowYear2.Offset... line but exits via the ElseIf line.
The Row Variable
I hate the idea of declaring a variable Row. But it is valid. Since there is an Offset involved, Row should be a range, probably a cell. As in the comments indicated, it has to 'survive' from another UserForm let's say UserFormX. If it has 'survived' you have to refer to it like this:
UserFormX.Row
or you have to declare it in a 'not-object' module to use only Row.
Another EnterBtn_Click
Probably useless now but here is the code I worked on the other day:
Option Explicit
Public intAttempts As Integer
Private Sub CancelBtn_Click()
Unload Me
End Sub
Private Sub EnterBtn_Click()
Const strEmail = "Please enter email address." ' Email Input Message
Const strPassword = "Please enter a password." ' Password Input Message
Const strLoginCorrect = "Welcome" ' Correct Login Message
Const strLoginIncorrect = "Incorrect Login." ' Incorrect Login Message
Const strAttempts = "Too many login attempts." ' Login Attempts Message
' Use worksheet name or index e.g. "SInfo" or 1.
Const vntWsName As String = "StudentInformation" ' Worksheet
' Use column letter or column number e.g. "F" or 6.
Const vntEmailColumn As Variant = "F" ' Email Column
Const intFirstRow As Integer = 2 ' Email Column First Row
Const intPasswordColumnOffset As Integer = -4 ' Password Column Offset
Const intMaxAttempts As Integer = 3 ' Maximum Login Attempts
Dim lngCounter As Long ' Email Column Row Counter
Dim lngLastrow As Long ' Email Column Last Row
' Check number of login attempts.
If intAttempts >= intMaxAttempts Then
MsgBox strAttempts
Exit Sub
End If
' Show annoying text messages if nothing was entered.
If Me.EmailTxt.Text = "" Then
Me.EmailTxt.Text = strEmail: Exit Sub
ElseIf Me.EmailTxt.Text = strEmail Then Exit Sub
End If
If Me.PasswordTxt.Text = "" Then
Me.PasswordTxt.Text = strPassword: Exit Sub
ElseIf Me.PasswordTxt.Text = strPassword Then Exit Sub
End If
' Check for data in specified worksheet.
With ThisWorkbook.Worksheets(vntWsName)
' Determine last row of data in Email Column.
lngLastrow = .Cells(Rows.Count, vntEmailColumn).End(xlUp).Row
For lngCounter = intFirstRow To lngLastrow
' Ceck for email in Email Column.
If UCase(.Cells(lngCounter, vntEmailColumn).Value) _
= UCase(EmailTxt.Text) Then ' Correct email.
' Check if correct password in Password Column
If UCase(.Cells(lngCounter, vntEmailColumn) _
.Offset(0, intPasswordColumnOffset).Value) _
= UCase(PasswordTxt.Text) Then ' Correct password.
Exit For
Else ' Wrong password. Set "counter" to "end".
' Faking that the loop was not interrupted.
lngCounter = lngLastrow
End If
' Else ' Wrong Email. Do nothing. Not necessary.
End If
Next
' When the loop wasn't interrupted, "lngcounter = lnglastrow + 1".
End With
' Check if loop was NOT interrupted.
If lngCounter = lngLastrow + 1 Then ' Loop was NOT interrupted.
intAttempts = intAttempts + 1
MsgBox strLoginIncorrect
Else ' Loop was interrupted. Correct email and password.
MsgBox strLoginCorrect
Unload Me
NewForm.Show
End If
End Sub

Finding a phrase in a string variable

I am trying to find a phrase inside of a variable that contains html. I then want to replace it with a new phrase.
I tried InStr but the phrase is not found. I also tried using wildcards at tht beginning and end of the phrase. I also tried doing an if like also with and without wildcards.
The purpose is to allow a tester to do a batch change on expected results and/or test steps by entering a sentence or phrase they want changed.
The only problem I'm having is being able to programmatically find the sentence within the variable.
Problem area is in bold
Dim qcURL As String
Dim qcID As String
Dim qcPWD As String
Dim qcDomain As String
Dim qcProject As String
Dim preActVal As String
Dim postActVal As String
Dim FindSt As String
Dim currentString As String
Dim thisSheet As Worksheet
'Toggle debugging mode'
Dim isDebugOn As Boolean
isDebugOn = True 'set to true to turn off Active X
''On Error GoTo ErrHandler:
FOLDER_PATH = "BAT\PC2P - Claims - Med"
Set thisSheet = ThisWorkbook.Sheets("ShellUpdater")
TestID = thisSheet.Range("B1").Value
stField = thisSheet.Range("B2").Value
**FindSt = thisSheet.Range("B3").Value**
ReplaceSt = thisSheet.Range("B4").Value
testLocation = thisSheet.Range("B5").Value
'ActiveX Forms
If isDebugOn = False Then
'qcURL = GetOptionMetric("qcURL", 1, "Enter ALM URL") ''popup to get url from user
qcURL = "<<URL>>"
'qcDomain = GetOptionMetric("qcDomain", 1, "Enter your ALM Domain")
''popup to get domain from user
qcDomain = "<<DOMAIN>>"
'qcProject = GetOptionMetric("qcProject", 1, "Enter your ALM Project")
''popup to get project from user
qcProject = "<<PROJECT>>"
qcID = GetOptionMetric("qcID", 1, "Enter your ALM MSID")
qcPWD = GetOptionPassword("qcPWD", 1, "Enter your ALM Password")
Else
qcURL = "<<URL>>"
qcID = "<<USERNAME>>"
qcDomain = "<<DOMAIN>>"
qcProject = "<<PROJECT>>"
qcPWD = InputBox("THIS IS IN DEEBUG MODE")
If qcPWD = vbNullString Then Exit Sub
If qcPWD = "" Then Exit Sub
End If
'END ActiveX Forms
'Connect to ALM
Set tdConnection = CreateObject("TDApiOle80.TDConnection")
tdConnection.InitConnectionEx qcURL
tdConnection.Login qcID, qcPWD
tdConnection.Connect qcDomain, qcProject
''Check if batch updating or single case
Dim testObject As ITest
If InStr(TestID, "All") > 0 Then
Dim TestFact As testFactory
Set tMng = tdConnection.TreeManager
Set srcFolder = tMng.NodeByPath("Subject\" & testLocation)
Set tstFact = srcFolder.testFactory
Set tstList = tstFact.NewList("")
For Each shellTest In tstList
Set DSFact = shellTest.DesignStepFactory.NewList("")
For Each dStep In DSFact
Select Case stField
Case "StepExpectedResult"
**currentString = dStep.StepExpectedResult**
**stposition = InStr(currentString, FindSt)**
If stposition > 0 Then
dStep.StepExpectedResult = preActVal & Replace(currentString, FindSt, ReplaceSt) & postActVal
End If
Case "StepDescription"
currentString = dStep.StepDescription
stposition = InStr(currentString, FindSt)
If stposition > 0 Then
dStep.StepDescription = preActVal & Replace(currentString, FindSt, ReplaceSt) & postActVal
End If
End Select
dStep.Post
Next dStep
Next shellTest
Else
Dim myTest
'Find the Test in test plan
Set thisTest = GetTest(Trim(TestID), testLocation, "\")
Set myTest = tdConnection.testFactory.Item(TestID)
End If
Try this:
Sub replace_string()
FindSt = "but also need rendering provider first name"
ReplaceString = "I LIKE BANANAS"
currentString = "All fields populate from the correctly populated provider<<<\!Renderingproviderlastname>>>, but also need rendering provider first name"
stPosition = Replace(currentString, FindSt, ReplaceString)
MsgBox stPosition
End Sub

When reading down a column of Excel file, how to define cell coordinates without selecting a cell?

Can anyone tell me how to improve this macro?
All the macro does is it just reads an Excel file for a list a accounts to update in an application (SmarTerm Beta). It technically already accomplishes the goal, but is there a way to code it so that while it’s reading the Excel file, the coordinates of the cells from which to read the account numbers and also the coordinates of the cells in which to write an output don’t depend on a "pre-selected" a cell? The risk with selecting a cell is that if someone were to accidentally select a different cell while the macro is running, everything will get screwed up.
Here's my current code:
Public oExcelObj As Object
Function WaitSystem(Optional NoDialog as Variant) As Boolean
Dim nContinue as Integer
Dim nTimeOut as Integer 'In seconds.
'The default timeout for each command is 3 minutes.
'Increase this value if your host requires more time
'for each command.
nTimeOut = 10
If IsMissing(NoDialog) then NoDialog = False
'Wait for response from host.
Session.EventWait.Timeout = nTimeOut
Session.EventWait.EventType = smlPAGERECEIVED
Session.EventWait.MaxEventCount = 1
WaitSystem = True
If Session.EventWait.Start = smlWAITTIMEOUT Then
If NoDialog Then
WaitSystem = False
Else
nContinue = QuerySyncError()
If nContinue <> ebYes then WaitSystem = False
End If
End If
Set LockStep = Nothing
End Function
'Establish link. Search for Excel.
Function OleLinkConnection
Const XlMaximized = &HFFFFEFD7
Titlebar$ = AppFind$("Microsoft Excel")
If Titlebar$ <> "" Then
bIsExcelActive = True
If AppGetState(Titlebar$) = ebMinimized Then
AppSetState 2, Titlebar$
End If
Else
bIsExcelActive = False
End If
If bIsExcelActive Then
'Create Excel Object using current instance of Excel.
Set oExcelObj = GetObject(, "Excel.Application")
Else
'Create Excel Object using a new instance of Excel.
Set oExcelObj = CreateObject("Excel.Application")
End If
Version = oExcelObj.Application.Version
oExcelObj.ScreenUpdating = True
oExcelObj.Displayalerts = True
oExcelObj.Visible = true
End Function
Sub JPBmacro
Dim AccountNumber As String
Dim Temp As Integer
Begin Dialog StartDialogTemplate ,,211,74,"Run JPBmacro?"
OKButton 60,12,92,20,.Proceed
CancelButton 60,40,92,20,.Exit
End Dialog
Dim StartDialog As StartDialogTemplate
r% = Dialog(StartDialog)
If r% = 0 Then End
g$ = "G:\DATA\outputfile.xlsx"
oleCode = OleLinkConnection
oExcelObj.Workbooks.Open g$
oExcelObj.Range("A1").Select ‘<----This selects the cell from which all coordinates are based off of. The coordinates of oExcelObj.ActiveCell.Offset(Y,X).Value VBA depend on selecting a cell.
NEXTACCOUNT:
Temp = 0
AccountNumber = oExcelObj.ActiveCell.Offset(Temp,0).Value
While AccountNumber <> ""
Session.SendKey "CLEAR"
If WaitSystem = False Then End
Session.Send "ACTU " & AccountNumber
Session.SendKey "ENTER"
If WaitSystem = False Then End
If Trim(Session.ScreenText(4,6,1,22)) = "INVALID ACCOUNT NUMBER" Or Trim(Session.ScreenText(4,6,1,19)) = "ACCOUNT NOT ON FILE" Then
oExcelObj.ActiveCell.Offset(Temp,1).Value = Trim(Session.ScreenText(4,6,1,22))
GoTo RESTARTLOOP
End If
UPDATEIOV:
If Trim(Session.ScreenText(13,76,1,1)) = "Y" Then
oExcelObj.ActiveCell.Offset(Temp,1).Value = "Account already flagged as institutional."
Else
Session.Row = 13
Session.Column = 76
Session.send "Y"
Session.SendKey "ENTER"
If WaitSystem = False Then End
oExcelObj.ActiveCell.Offset(Temp,1).Value = Trim(Session.ScreenText(24,2,1,50))
End If
RESTARTLOOP:
Temp = Temp + 1
AccountNumber = oExcelObj.ActiveCell.Offset(Temp,0).Value
Wend
ENDNOW:
oExcelObj.Workbooks.Close
MsgBox "All Done!"
End Sub
Why not keep the reference to the first cell?
Dim rng as Range
Set rng = oExcelObj.Range("A1")
i=1
...
x = rng.Cell(i,1).Value
'Or faster yet is reading all the values into an variant array.
Dim array() as Variant
array = rng.Resize(N,M).Value
' Work with array as
x = array(i,1)
Given the comment from assylias and that another poster has since "answered" with this approach:
I can't see where oExcelObj is instantiated? Or how you are referring to a specific sheet.
Regardless of which,
you can avoid select by setting a range, ie Set rng1 = oExcelObj.Sheets(1).Range("A1")
and then use offsets from rng1.
The user won't be able to interfere while the code is running

how to determine a different entry in a field in lotus notes

I have an Add button in the dialog form to add items, its quantity, price , currency and list in the field below. There is a currency field in the form. it is a drop down list with many currencies. The currency should be same on adding the items. if there is currency change, message box should appear. below is the part of the code for add button event. "cur" is the currency field.
Sub Click(Source As Button)
'On Error Goto errhandle
Dim work As New notesuiworkspace
Dim uidoc As notesuidocument
Dim doc As notesdocument
Dim item As String, weight As String
Dim qty As String, price As String
Dim sbtotal As String
Dim gtotal As String
Set uidoc = work.currentdocument
Set doc =uidoc.Document
item = uidoc.FieldGetText("Item")
qty = uidoc.FieldGetText("Qty")
price = uidoc.FieldGetText("Price")
cur = uidoc.FieldGetText("cur")
sbtotal= uidoc.FieldGetText("SubTotal")
Call uidoc.Refresh
'weight = uidoc.FieldGetText("W_Qty")
'adj = uidoc.fieldGetText("Adj")
remark = uidoc.FieldGetText("Remarks")
If item = "" Or qty = "" Or price = "" Then
Msgbox "Please complete the data entry ", 16, "Error - Incomplete Data Entry"
Exit Sub
End If
recordNo = uidoc.fieldgettext("ww")
If recordNo = "" Then
recordNumber = 0
Else
pos = Instr(recordNo,";")
If pos > 0 Then
number = Right(recordNo , pos -1)
Else
number = Left(recordNo , pos +1)
End If
recordNumber = Cint(number)
End If
recordNumber = recordNumber + 1
'to append text
Call uidoc.FieldAppendText("no" ,";" & Cstr(recordNumber))
Call uidoc.FieldAppendText("Item1" ,";" & item)
Call uidoc.FieldAppendText("Q1" , ";" & Cstr(qty))
Call uidoc.FieldAppendText("amt" , ";" & Cdbl(price))
Call uidoc.FieldAppendText("C1" , ";" & Cstr(cur))
Call uidoc.FieldAppendText("TSubTotal" , ";" & Cdbl(sbtotal))
'clear entering data
uidoc.FieldClear("Remarks")
uidoc.FieldClear("Item")
uidoc.FieldClear("Qty")
uidoc.FieldClear("Price")
'uidoc.FieldClear("W_Qty")
Call uidoc.FieldSetText("SubTotal","0.00")
uidoc.refresh
Dim subtotal As Double
subtotal = 0
Forall stotal In doc.TSubTotal
If stotal <> "" Then
subtotal = subtotal + Cdbl(stotal)
End If
End Forall
total = subtotal '+ Cdbl(curdoc.SubTotal(0))
Call uidoc.FieldSetText("GrandTotal",Format(total,"#,##0.00"))
uidoc.refresh
uidoc.gotofield"Item"
End Sub
Please help me. Thanks.
Create a new hidden field called selectedCurrency. The initial value of this field should be empty.
In your Add button code, you need to first check selectedCurrency, and if it is blank you should set it equal to cur.
Then, also in the code for the Add button, you need to compare selectedCurrency and cur, and if they are not equal you should display your message box.
I'd fix the currency outside the code for the Add button, and also make it required before Add can be started.

Resources