Solved

Giving a Form a Unique ID

Posted on 2006-06-22
8
220 Views
Last Modified: 2008-02-26
Hey Experts

I am making POS Software and I need to give each transaction form and unique id

I tried

Private Sub CmdSaleToClient_Click()

Dim frm As New frmSaleToClient

Transcode = Transcode + 1

frm.Caption = Transcode

frm.Show

End Sub

But it does not work when you get to the main bill screen

The problem is if you open say 5 transactions it opens five form each with a different transaction ID but if I go to transaction form 1 and go to the main bill screen the transaction id changes to 5.

Please Help

Nothern_Lights
0
Comment
Question by:Nothern_Lights
  • 3
  • 3
  • 2
8 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 16959085
Hi Nothern_Lights,

Is this an MDI application or an SDI application? The key really to either is to determine exactly what happens, you have the relevant transcode in each form's caption so this is what you could use. Personally I would store this in the form's .Tag property but caption is fine.

It depends on how you activate the main form from each transaction, you may be able to set a property in the main form from the last activated transaction form for example.

Tim Cottee
0
 

Author Comment

by:Nothern_Lights
ID: 16959390
Hey Tim

What is the difference between MDI and SDI application?

In the frmSaleToClient properties I have in the caption "Sale To Client"

And I use code to change the form caption to the transaction ID but when I read the form caption I get “Sale To Client” but on the screen is has the Transaction ID

I tried storing the Transaction ID in the Form Tag but i still got the same problem for so weird reason

Thanks

Nothern_Lights
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 16959419
Nothern_Lights,

Firstly, MDI - multiple document interface, where you have a parent form and child forms are contained and constrained within it. SDI - Single Document Interface, here you can still have multiple forms but they are effectively only constrained by the desktop. Word and excel are good examples of an MDI interface, though these days you can make them work in a pseudo-SDI way as well.

The reason you still get "Sale To Client" I would expect is that you are not referencing the form you think you are. Because you are creating new instances of the same base form, if you refer to "frmSaleToClient.Caption" it will actually open a hidden instance of the base form and that is the one you are probably getting the information from. You could probably use ActiveForm.Caption / ActiveForm.Tag to determine which form you are currently referring to. This will work excellently in an MDI interface but perhaps not so well in SDI.

Tim
0
 
LVL 17

Expert Comment

by:inthedark
ID: 16959428
MDI - Multiple Document Interface
SDI - Single Document Interface
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 17

Expert Comment

by:inthedark
ID: 16959471
See solution here.
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_21891753.html

I think that by declaring the form with the new keyword the form load event fires first before the current sub executes.


Dim frm As New frmSaleToClient

Change to:

Dim frm As frmSaleToClient
set frm = New frmSaleToClient


0
 

Author Comment

by:Nothern_Lights
ID: 16959543
Tim

I can only get ActiveForm.Caption / ActiveForm.Tag to work using MDI form

I would prefer to not to use MDI use SDI instead

Thanks

Nothern_Lights
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 500 total points
ID: 16959579
Nothern_Lights,

So what you have to do in that situation then is to update a property on your main form each time you activate one of your transaction forms. Something like:

In Main Form:

Private _CurrentTransaction As Integer


Public Property Let CurrentTransaction(ByVal TransactionNumber As Integer)
    _CurrentTransaction = TransactionNumber
End Property

Public Property Get CurrentTransaction() As Integer
    CurrentTransaction = _CurrentTransaction
End Property

This will allow your other forms to set this property so that you can use it in the main form.

Then in the frmSaleToClient form have:

Private Sub Form_Activate()
    MainForm.CurrentTransaction = Me.Tag
End Sub

So whenever you click on one of the transaction forms, the property in your main form will be set to the value of that transaction form's .Tag property. This way your main form can know which was the last selected transaction form.

Tim
0
 

Author Comment

by:Nothern_Lights
ID: 16961853
Thanks For All your Help Tim

Nothern_Lights
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now