Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code needed to get past a blank text box!

Status
Not open for further replies.

BH

Programmer
Oct 15, 2002
76
GB
Can anyone help with this bit of coding? What I am trying to do is copy contents of a text box (Address1) in one form, then go into another form and paste the information into another text box (Form2 Address1). Return to the original form copy the next text box (Address2) and return to the next form and paste into Form2 Address2.

This is repeated for Address3, Address4, Address5 and Postcode.

The code below work fine with no problems until there is a blank space in one of the Address text boxes i.e.

Address1: Fred Bloggs House
Address2: Blogg Street
Address3: Blogg City
Address4: Bloggshire
Address5:
Postcode: BL0 0GG

It does not then go past the blank field and only copies upto Address4.

Can anyone get me past this blank please!

The code I have wrote is

Private Sub Command20_Click()

Dim stDocName As String
Dim stLinkCriteria As String

On Error GoTo copypaste_copypaste_Err

stDocNameContact = "Contact Form"
stDocNameAddress = "Address List"

DoCmd.GoToControl "[Address 1]"
DoCmd.RunCommand acCmdCopy

DoCmd.OpenForm stDocNameContact, , , stLinkCriteria

DoCmd.GoToControl "[Address 1]"
DoCmd.RunCommand acCmdPaste

DoCmd.OpenForm stDocNameAddress, , , stLinkCriteria

DoCmd.GoToControl "[Address 2]"
DoCmd.RunCommand acCmdCopy

DoCmd.OpenForm stDocNameContact, , , stLinkCriteria

DoCmd.GoToControl "[Address 2]"
DoCmd.RunCommand acCmdPaste

DoCmd.OpenForm stDocNameAddress, , , stLinkCriteria

DoCmd.GoToControl "[Address 3]"
DoCmd.RunCommand acCmdCopy

DoCmd.OpenForm stDocNameContact, , , stLinkCriteria

DoCmd.GoToControl "[Address 3]"
DoCmd.RunCommand acCmdPaste

DoCmd.OpenForm stDocNameAddress, , , stLinkCriteria

DoCmd.GoToControl "[Address 4]"
DoCmd.RunCommand acCmdCopy

DoCmd.OpenForm stDocNameContact, , , stLinkCriteria

DoCmd.GoToControl "[Address 4]"
DoCmd.RunCommand acCmdPaste

DoCmd.OpenForm stDocNameAddress, , , stLinkCriteria

DoCmd.GoToControl "[Address 5]"
DoCmd.RunCommand acCmdCopy

DoCmd.OpenForm stDocNameContact, , , stLinkCriteria

DoCmd.GoToControl "[Address 5]"
DoCmd.RunCommand acCmdPaste

copypaste_copypaste_Err:
MsgBox "Address Copied OK "

End Sub

Thanks for your time

BH
 
I wrote it for just one. Add these in for the copy commands, and it should work. (Not sure if the != means 'NOT EQUAL' in VB.

If Address 1 != "" Then
DoCmd.GoToControl "[Address 1]"
DoCmd.RunCommand acCmdCopy
End If

Hope this helps you.

Jon
 
Hi, this should do it. If the address field is not null, copy/paste otherwise do nothing and test next address field for null.

If Not IsNull([Address 1]) Then
DoCmd.GoToControl "[Address 1]"
DoCmd.RunCommand acCmdCopy

DoCmd.OpenForm stDocNameContact, , , stLinkCriteria

DoCmd.GoToControl "[Address 1]"
DoCmd.RunCommand acCmdPaste

DoCmd.OpenForm stDocNameAddress, , , stLinkCriteria
End If

If Not IsNull([Address 2]) Then
DoCmd.GoToControl "[Address 2]"
DoCmd.RunCommand acCmdCopy

DoCmd.OpenForm stDocNameContact, , , stLinkCriteria

DoCmd.GoToControl "[Address 2]"
DoCmd.RunCommand acCmdPaste

DoCmd.OpenForm stDocNameAddress, , , stLinkCriteria
End If

If Not IsNull([Address 3]) Then
DoCmd.GoToControl "[Address 3]"
DoCmd.RunCommand acCmdCopy

DoCmd.OpenForm stDocNameContact, , , stLinkCriteria

DoCmd.GoToControl "[Address 3]"
DoCmd.RunCommand acCmdPaste

DoCmd.OpenForm stDocNameAddress, , , stLinkCriteria
End If

If Not IsNull([Address 4]) Then
DoCmd.GoToControl "[Address 4]"
DoCmd.RunCommand acCmdCopy

DoCmd.OpenForm stDocNameContact, , , stLinkCriteria

DoCmd.GoToControl "[Address 4]"
DoCmd.RunCommand acCmdPaste

DoCmd.OpenForm stDocNameAddress, , , stLinkCriteria
End If

If Not IsNull([Address 5]) Then
DoCmd.GoToControl "[Address 5]"
DoCmd.RunCommand acCmdCopy

DoCmd.OpenForm stDocNameContact, , , stLinkCriteria

DoCmd.GoToControl "[Address 5]"
DoCmd.RunCommand acCmdPaste
End If
 
Brilliant

A real big thank you jsaliers and billpower for your time

You have managed to get me round the problem, everything now works as I want it to

Thanks again

BH

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top