We use an Excel UserForm to update a dynamic Sales database.
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com
ffice
ffice" /><o
></o
>
A) The UserForm has the following textboxes:
<o
></o
>
></o
>
When a Sales Invoice is generated, we enter the above details in the UserForm (in respect of each invoice) to enable us to update the Sales database.
<o
></o
>
To do that, we use the following codes:
C) TO UPDATE DATABASE WITH RECEIPTS:
When payment for any of the invoices is received, and in order to update the database with such receipt, we want to be able to key into a UserForm only two pieces of data, namely:
<o
></o
>
></o
>
and plan to use a VBA code to find, in the database, the paid Invoice No. , and find the cell against that invoice number containing the word ‘Unpaid’, and then replace the word ‘Unpaid’ with the date the invoice is paid (in “dd/mm/yyyy” format).
<o
></o
>
We currently do the receipts updating in a cumbersome way – listing on a separate excel sheet (named ‘Receipts’) the ‘invoice numbers’ & ‘the date paid’ in columns A & B, respectively, for all paid invoices. We then start clicking each date with a mouse to achieve the updating. The VBA we use for this purpose is as follows:
Code for RECEIPTS: in Worksheet - Change
Please, we want to be able to use a single excel UserForm for both ‘Sales Invoice Data Entry’ as explained in Paragraph (B) above and also to update the database with ‘Receipts’.
<o
></o
>
Please can someone help us with a vba ‘Receipts’ code that we can combine with the Sales Invoice Data Entry code in (B) above so that when we enter the ‘Invoice No. paid’ and the ‘Date Paid’ in the excel UserForm, the relevant Invoice No. paid will be found in the database and the cell for that invoice number containing the word ‘Unpaid’ will be replaced with the ‘date paid’.
<o
></o
>
If the two processes can be achieved using one UserForm, that will be good. I’ll be happy to re-design the current Sales Invoice Data Entry UserForm & change the textboxes listed in (A) above. If it is not possible to achieve this using one UserForm, we will be glad to use two different UserForms if we can get help with the vba code, please for the ‘Receipts’ update, please.
<o
></o
>
Thank you for your anticipated help.
<o
></o
>
<o
>Kenny</o
>
<o
></o
>
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com
A) The UserForm has the following textboxes:
<o
- Invoice No.
- Invoice Date
- Gross Amount
- Vat Amount
- Net Amount
- Type in ‘Unpaid’ (In this box we type in the word ‘Unpaid’ cos we find it helpful for Pivot Table analysis.<o
></o
>
When a Sales Invoice is generated, we enter the above details in the UserForm (in respect of each invoice) to enable us to update the Sales database.
<o
To do that, we use the following codes:
Code:
[FONT=Arial]Private Sub cmdAdd_Click()<o:p></o:p>[/FONT]
[FONT=Arial]Dim iRow As Long<o:p></o:p>[/FONT]
[FONT=Arial]Dim ws As Worksheet<o:p></o:p>[/FONT]
[FONT=Arial]Set ws = Worksheets("SalesData")<o:p></o:p>[/FONT]
<o:p></o:p>
[FONT=Arial]'find first empty row in database<o:p></o:p>[/FONT]
[FONT=Arial]On Error Resume Next<o:p></o:p>[/FONT]
<o:p></o:p>
[FONT=Arial]iRow = ws.Cells(Rows.Count, 1) _<o:p></o:p>[/FONT]
[FONT=Arial].End(xlUp).Offset(1, 0).Row<o:p></o:p>[/FONT]
[FONT=Arial]<o:p></o:p>[/FONT]
[FONT=Arial]'check for Invoice Number<o:p></o:p>[/FONT]
[FONT=Arial]If Trim(Me.txtInv.Value) = "" Then<o:p></o:p>[/FONT]
[FONT=Arial]Me.txtInv.SetFocus<o:p></o:p>[/FONT]
[FONT=Arial]MsgBox "Please Enter Sales Data or Click 'Close Form' to Exit", vbExclamation, "Sales Data Entry"<o:p></o:p>[/FONT]
[FONT=Arial]Exit Sub<o:p></o:p>[/FONT]
[FONT=Arial]End If<o:p></o:p>[/FONT]
<o:p></o:p>
[FONT=Arial]' Check user input<o:p></o:p>[/FONT]
[FONT=Arial]If Not IsDate(Me.txtDate.Value) Then<o:p></o:p>[/FONT]
[FONT=Arial]MsgBox "You Must enter a Date in the 'Date' Box.", vbExclamation, "Sales Data Entry"<o:p></o:p>[/FONT]
[FONT=Arial]Me.txtDate.SetFocus<o:p></o:p>[/FONT]
[FONT=Arial]Exit Sub<o:p></o:p>[/FONT]
[FONT=Arial]End If<o:p></o:p>[/FONT]
<o:p></o:p>
[FONT=Arial]'copy the data to the database<o:p></o:p>[/FONT]
[FONT=Arial]ws.Cells(iRow, 1).Value = Me.txtInv.Value<o:p></o:p>[/FONT]
[FONT=Arial]ws.Cells(iRow, 2).Value = Me.txtDate.Value <o:p></o:p>[/FONT]
[FONT=Arial]ws.Cells(iRow, 4).Value = Me.txtGross.Value<o:p></o:p>[/FONT]
[FONT=Arial]ws.Cells(iRow, 5).Value = Me.txtVat.Value<o:p></o:p>[/FONT]
[FONT=Arial]ws.Cells(iRow, 6).Value = Me.txtNet.Value<o:p></o:p>[/FONT]
[FONT=Arial]ws.Cells(iRow, 7).Value = Me.txtDP<o:p></o:p>[/FONT]
<o:p></o:p>
<o:p></o:p>
[FONT=Arial]'clear the data<o:p></o:p>[/FONT]
[FONT=Arial]Me.txtInv.Value = ""<o:p></o:p>[/FONT]
[FONT=Arial]Me.txtDate.Value = ""<o:p></o:p>[/FONT]
[FONT=Arial]Me.txtGross.Value = ""<o:p></o:p>[/FONT]
[FONT=Arial]Me.txtVat.Value = ""<o:p></o:p>[/FONT]
[FONT=Arial]Me.txtNet.Value = ""<o:p></o:p>[/FONT]
[FONT=Arial]Me.txtDP.Value = ""<o:p></o:p>[/FONT]
<o:p></o:p>
[FONT=Arial]End Sub<o:p></o:p>[/FONT]
<o:p></o:p>
[FONT=Arial]Private Sub cmdClose_Click()<o:p></o:p>[/FONT]
[FONT=Arial] Unload Me<o:p></o:p>[/FONT]
[FONT=Arial]End Sub<o:p></o:p>[/FONT]
C) TO UPDATE DATABASE WITH RECEIPTS:
When payment for any of the invoices is received, and in order to update the database with such receipt, we want to be able to key into a UserForm only two pieces of data, namely:
<o
- The Invoice No.
- The Date Paid.
and plan to use a VBA code to find, in the database, the paid Invoice No. , and find the cell against that invoice number containing the word ‘Unpaid’, and then replace the word ‘Unpaid’ with the date the invoice is paid (in “dd/mm/yyyy” format).
<o
We currently do the receipts updating in a cumbersome way – listing on a separate excel sheet (named ‘Receipts’) the ‘invoice numbers’ & ‘the date paid’ in columns A & B, respectively, for all paid invoices. We then start clicking each date with a mouse to achieve the updating. The VBA we use for this purpose is as follows:
Code for RECEIPTS: in Worksheet - Change
Code:
[FONT=Arial]Private Sub Worksheet_Change(ByVal Target As Range)<o:p></o:p>[/FONT]
[FONT=Arial] Dim r As Range<o:p></o:p>[/FONT]
[FONT=Arial] If Target.Column = 2 Then<o:p></o:p>[/FONT]
[FONT=Arial] Set r = Sheets("data table").Range("a:a").Find(Target.Offset(, -1))<o:p></o:p>[/FONT]
[FONT=Arial] If Not r Is Nothing Then<o:p></o:p>[/FONT]
[FONT=Arial] r.Offset(, 6) = Target<o:p></o:p>[/FONT]
[FONT=Arial] Else<o:p></o:p>[/FONT]
[FONT=Arial] MsgBox "invoice " & Target.Offset(, -1) & " is not found" ' do whatever if invoice is not found<o:p></o:p>[/FONT]
[FONT=Arial] End If<o:p></o:p>[/FONT]
[FONT=Arial] End If<o:p></o:p>[/FONT]
[FONT=Arial] End Sub<o:p></o:p>[/FONT]
Please, we want to be able to use a single excel UserForm for both ‘Sales Invoice Data Entry’ as explained in Paragraph (B) above and also to update the database with ‘Receipts’.
<o
Please can someone help us with a vba ‘Receipts’ code that we can combine with the Sales Invoice Data Entry code in (B) above so that when we enter the ‘Invoice No. paid’ and the ‘Date Paid’ in the excel UserForm, the relevant Invoice No. paid will be found in the database and the cell for that invoice number containing the word ‘Unpaid’ will be replaced with the ‘date paid’.
<o
If the two processes can be achieved using one UserForm, that will be good. I’ll be happy to re-design the current Sales Invoice Data Entry UserForm & change the textboxes listed in (A) above. If it is not possible to achieve this using one UserForm, we will be glad to use two different UserForms if we can get help with the vba code, please for the ‘Receipts’ update, please.
<o
Thank you for your anticipated help.
<o
<o
<o
Last edited: