Link Text Boxes on separate forms

N

Nick T

Hi,

Can i link two text boxes on separate forms??

eg, if i have two forms open, and i input data into a text box on 'form1'
can i get this to automatically input into a text box on 'form 2'?

Any suggestions.
Thanks
 
B

Beetle

Why do you want to do that? Are you redundantly storing data in two
different tables (which is usually not a good idea)?
 
N

Nick T

Hi,

Well, really, im trying to figure out a way to use command buttons to input
numbers into different text boxes on a form. Im struggling using a 'number
keypad' style layout on the same form as my text boxes, so thought that if i
had a separate 'keypad' form for each text box on my main form i could link
them?? (hope im making sense).

Iv copied below a thread with background on my query & suggestions, from
others, however i still cant find a solution! Any help appreciated!

The thread:..............

Hi,
This is frustrating me now - wish i never started!!
Hope you can help again.......

What do you mean by pasting the code in 'declarations' what are these &
where do i paste the code you have suggested?

Thanks
Nick



Rastro said:
I forgot something:
The process is this:
select the textbox (eg. textbox1) then click 1, 4, 7, 2, whatever button,
and then click btnSetText and you'll see
"1472whatever button" in the textbox1.

After this you should select other textbox or the textbox1 text will be
replaced with the new text.
 
B

Beetle

I read through the thread, and I would have to agree with Jeff and Rastro.
This is an extremely complicated solution to an exceedingly simple task. I
did not see anywhere in the thread where you really say *why* you want
to do this. Do you live in some strange land where the keyboards have no
number keys?

If you really are determined to do it that way, then the examples that Rastro
provided should work. In your last post from the previous thread, you were
asking about the declarations. At the top of the code module, just below
where it says -

Option Compare Database
Option Explicit

- is where you can declare module variables that can be used by any procedure
in the module.

As far as your current attempt at having a separate "number pad" for each
text box, I think that is only going to add more comlexity to an already
overcomplicated situation.
 
N

Nick T

Hi, thanks for taking the time to read through - complex & frustrating i know.
My database will be used on touch screen handheld pc's (samsung Q1) which
needs to be extremly user friendly - its designed to minimise user input
errors so i need it as simple as poss (for the end users).
Basically, a user shall enter an 'order number' into a text box (using the
10 command buttons numbered 0-9). Then they shall press an 'accept' button,
which will SetFocus to another text box. They then scan a barcode which will
put a number into another text box (which AfterUpdate, will SetFocus to
another text box). In this last text box, they shall enter the quantity of
the product they have prevousley scanned using the same "number key pad" they
used to input the order number into the first text box.

Where prevousley i have used the following code to input more than one of
the same number into a text box:

Me.TextBoxName = Me.TextBoxName & "1"

However this code in a command button's event is obvousley only going to put
the number into one text box (in this case being one named 'TextBoxName')

I hope this makes my situation a little clearer as any help you could offer
would be greatly appreciated.

many thanks
Nick

Ps. sorry for long winded explanation - you did ask!.
 
B

Beetle

Ps. sorry for long winded explanation - you did ask!.

No problem. Now that you've explained it, that is an interesting problem.
I see your dilemma. I think that Rastro's ideas should work, but maybe
needs to be expanded on a bit. You may also need some code to control
which text box gets focus at a given time while the record is being built.

I'll give it some thought and post back. Meanwhile, maybe one of the
Access studs in the group will pickup on this thread and offer some advice.
 
B

Beetle

OK, I came up with *might* be a workable solution. I say might because
I know very little about your app, so there may be reasons why this won't
work for you. If you decide to try this method, backup your db first and
make a test copy to work on (hopefully you're already doing that anyway).
Make sure you test it thoroughly before you try to implement it in your
actual application. There could be some fatal flaw in my logic that I'm not
seeing. If so, hopefully one of the experts in the group will pop in and
point out my colossal stupidity :). Even if you can't do it this way for
some reason, maybe it will give you some ideas to try.

Anyway, I created a simple db with one table and one form. I decided to use
an unbound form, on the premise that it may be better not commit any
values to the table until the user clicks a "Save" button.

My table has three fields (FirstNumber, SecondNumber, ThirdNumber) that
are all long integer data type

My form has the following controls;

Three unbound text boxes (txt1, txt2, txt3)

Three hidden check boxes (chkStep1, chkStep2, chkStep3) to help control
the process of moving through the form

Ten "keypad" command buttons number 0 - 9 with names like;
cmd1 (with a caption of 1)
cmd2 (with a caption of 2)
etc.

Three other command buttons (cmdContinue, cmdUndo, cmdSave)

Now for the code. Keep in mind this code is a little rough. It could be
cleaned up a bit, but it does work (at least in my test db). And of course
you will have to change the naming of all the fields/controls. Also, I
put in some code to change the back color of each text box as you
move through the steps, which you may not want.

1) First, at the top of the module (right after Option Compare DB and Option
Explicit) put the following declaration

Dim strInputString As String

2) Code for the forms Open event;

Private Sub Form_Open(Cancel As Integer)

Me.chkStep1 = True
Me.chkStep2 = False
Me.chkStep3 = False
Me.txt1.BackColor = vbYellow
Me.txt2.BackColor = vbWhite
Me.txt3.BackColor = vbWhite

End Sub

3) Code for the "keypad" buttons;

Private Sub cmd1_Click()

strInputString = strInputString & Me.cmd1.Caption

If Me.chkStep1 = True Then
Me.txt1 = strInputString
ElseIf Me.chkStep3 = True Then
Me.txt3 = strInputString
Else
'we are on step 2 so do nothing
End If

End Sub

All other keypad buttons use the same code, with the name changed to
match the associated button.

4) Code for the "Continue" button;

Private Sub cmdContinue_Click()

strInputString = "" 'Reset the string variable to nothing before moving on

If Me.chkStep1 = True Then
Me.chkStep1 = False
Me.chkStep2 = True
Me.txt1.BackColor = vbWhite
Me.txt2.BackColor = vbYellow
ElseIf Me.chkStep2 = True Then
Me.chkStep2 = False
Me.chkStep3 = True
Me.txt2.BackColor = vbWhite
Me.txt3.BackColor = vbYellow
ElseIf Me.chkStep3 = True Then
Me.chkStep3 = False
Me.chkStep1 = True
Me.txt3.BackColor = vbWhite
Me.txt1.BackColor = vbYellow
End If

End Sub

5) Code for the "Undo" button;

Private Sub cmdUndo_Click()

strInputString = "" 'Reset the string variable to nothing

If Me.chkStep1 = True Then
Me.txt1 = Null
ElseIf Me.chkStep2 = True Then
Me.txt2 = Null
ElseIf Me.chkStep3 = True Then
Me.txt3 = Null
End If

End Sub

6) Code for the "Save" button;

Private Sub cmdSave_Click()

Dim con As adodb.Connection
Dim strSQL As String

If Nz(Me.txt1, "") = "" Or Nz(Me.txt2, "") = "" Or Nz(Me.txt3, "") = ""
Then
MsgBox "Please enter a value in each box before saving"
Exit Sub
End If

Set con = CurrentProject.Connection
strSQL = "Insert Into
Table1([FirstNumber],[SecondNumber],[ThirdNumber])" & _
" Values(" & Me.txt1 & "," & Me.txt2 & "," & Me.txt3 & ")"

con.Execute strSQL, dbFailOnError

strInputString = "" 'Reset the input string to nothing after saving
Me.txt1 = Null
Me.txt2 = Null
Me.txt3 = Null
Me.chkStep1 = True
Me.chkStep2 = False
Me.chkStep3 = False
Me.txt1.BackColor = vbYellow
Me.txt2.BackColor = vbWhite
Me.txt3.BackColor = vbWhite

End Sub

Finally, you will need to add your own error handling. Also, since the
second step of your procedure gets the value from a bar code scanner,
I didn't tackle that issue, so you'll have to add your own code for that.
(I'm not that familiar with using a bar code scanner with an Access db)
Plus, the e-mail editor will probably screw up the line wrap in the code
for the "Save" button, so that may need to be fixed.

Other random thoughts - You may want to change some things. For example
you may want to have the "Continue" button disabled when the user moves
to step three, so they can't accidently move back to step 1 before saving
the record, then enable it again in the save procedure. Or you may want
to add a "Clear" button so the user can clear the entire form and start over
if needed.

Anyway, that's my two cents worth. Happy coding :)
 
N

Nick T

Hiya,

Just got in from a manic day @ work & back on with my db!
Thanks for your help - really appreciate it - having a few teeting probs
with exactly how i envisage it to work, however its given me a great leap
forward!!

I think its going to work perfectly!!

Thanks again for your help!

Nick

Beetle said:
OK, I came up with *might* be a workable solution. I say might because
I know very little about your app, so there may be reasons why this won't
work for you. If you decide to try this method, backup your db first and
make a test copy to work on (hopefully you're already doing that anyway).
Make sure you test it thoroughly before you try to implement it in your
actual application. There could be some fatal flaw in my logic that I'm not
seeing. If so, hopefully one of the experts in the group will pop in and
point out my colossal stupidity :). Even if you can't do it this way for
some reason, maybe it will give you some ideas to try.

Anyway, I created a simple db with one table and one form. I decided to use
an unbound form, on the premise that it may be better not commit any
values to the table until the user clicks a "Save" button.

My table has three fields (FirstNumber, SecondNumber, ThirdNumber) that
are all long integer data type

My form has the following controls;

Three unbound text boxes (txt1, txt2, txt3)

Three hidden check boxes (chkStep1, chkStep2, chkStep3) to help control
the process of moving through the form

Ten "keypad" command buttons number 0 - 9 with names like;
cmd1 (with a caption of 1)
cmd2 (with a caption of 2)
etc.

Three other command buttons (cmdContinue, cmdUndo, cmdSave)

Now for the code. Keep in mind this code is a little rough. It could be
cleaned up a bit, but it does work (at least in my test db). And of course
you will have to change the naming of all the fields/controls. Also, I
put in some code to change the back color of each text box as you
move through the steps, which you may not want.

1) First, at the top of the module (right after Option Compare DB and Option
Explicit) put the following declaration

Dim strInputString As String

2) Code for the forms Open event;

Private Sub Form_Open(Cancel As Integer)

Me.chkStep1 = True
Me.chkStep2 = False
Me.chkStep3 = False
Me.txt1.BackColor = vbYellow
Me.txt2.BackColor = vbWhite
Me.txt3.BackColor = vbWhite

End Sub

3) Code for the "keypad" buttons;

Private Sub cmd1_Click()

strInputString = strInputString & Me.cmd1.Caption

If Me.chkStep1 = True Then
Me.txt1 = strInputString
ElseIf Me.chkStep3 = True Then
Me.txt3 = strInputString
Else
'we are on step 2 so do nothing
End If

End Sub

All other keypad buttons use the same code, with the name changed to
match the associated button.

4) Code for the "Continue" button;

Private Sub cmdContinue_Click()

strInputString = "" 'Reset the string variable to nothing before moving on

If Me.chkStep1 = True Then
Me.chkStep1 = False
Me.chkStep2 = True
Me.txt1.BackColor = vbWhite
Me.txt2.BackColor = vbYellow
ElseIf Me.chkStep2 = True Then
Me.chkStep2 = False
Me.chkStep3 = True
Me.txt2.BackColor = vbWhite
Me.txt3.BackColor = vbYellow
ElseIf Me.chkStep3 = True Then
Me.chkStep3 = False
Me.chkStep1 = True
Me.txt3.BackColor = vbWhite
Me.txt1.BackColor = vbYellow
End If

End Sub

5) Code for the "Undo" button;

Private Sub cmdUndo_Click()

strInputString = "" 'Reset the string variable to nothing

If Me.chkStep1 = True Then
Me.txt1 = Null
ElseIf Me.chkStep2 = True Then
Me.txt2 = Null
ElseIf Me.chkStep3 = True Then
Me.txt3 = Null
End If

End Sub

6) Code for the "Save" button;

Private Sub cmdSave_Click()

Dim con As adodb.Connection
Dim strSQL As String

If Nz(Me.txt1, "") = "" Or Nz(Me.txt2, "") = "" Or Nz(Me.txt3, "") = ""
Then
MsgBox "Please enter a value in each box before saving"
Exit Sub
End If

Set con = CurrentProject.Connection
strSQL = "Insert Into
Table1([FirstNumber],[SecondNumber],[ThirdNumber])" & _
" Values(" & Me.txt1 & "," & Me.txt2 & "," & Me.txt3 & ")"

con.Execute strSQL, dbFailOnError

strInputString = "" 'Reset the input string to nothing after saving
Me.txt1 = Null
Me.txt2 = Null
Me.txt3 = Null
Me.chkStep1 = True
Me.chkStep2 = False
Me.chkStep3 = False
Me.txt1.BackColor = vbYellow
Me.txt2.BackColor = vbWhite
Me.txt3.BackColor = vbWhite

End Sub

Finally, you will need to add your own error handling. Also, since the
second step of your procedure gets the value from a bar code scanner,
I didn't tackle that issue, so you'll have to add your own code for that.
(I'm not that familiar with using a bar code scanner with an Access db)
Plus, the e-mail editor will probably screw up the line wrap in the code
for the "Save" button, so that may need to be fixed.

Other random thoughts - You may want to change some things. For example
you may want to have the "Continue" button disabled when the user moves
to step three, so they can't accidently move back to step 1 before saving
the record, then enable it again in the save procedure. Or you may want
to add a "Clear" button so the user can clear the entire form and start over
if needed.

Anyway, that's my two cents worth. Happy coding :)

--
_________

Sean Bailey


Nick T said:
Hi, thanks for taking the time to read through - complex & frustrating i know.
My database will be used on touch screen handheld pc's (samsung Q1) which
needs to be extremly user friendly - its designed to minimise user input
errors so i need it as simple as poss (for the end users).
Basically, a user shall enter an 'order number' into a text box (using the
10 command buttons numbered 0-9). Then they shall press an 'accept' button,
which will SetFocus to another text box. They then scan a barcode which will
put a number into another text box (which AfterUpdate, will SetFocus to
another text box). In this last text box, they shall enter the quantity of
the product they have prevousley scanned using the same "number key pad" they
used to input the order number into the first text box.

Where prevousley i have used the following code to input more than one of
the same number into a text box:

Me.TextBoxName = Me.TextBoxName & "1"

However this code in a command button's event is obvousley only going to put
the number into one text box (in this case being one named 'TextBoxName')

I hope this makes my situation a little clearer as any help you could offer
would be greatly appreciated.

many thanks
Nick

Ps. sorry for long winded explanation - you did ask!.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top