#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,670
Default Code Review

Hello all, I got some fantastic help on this problem yesterday and wanted to
see if someone could take a look at my code and possibly offer some
suggestions.

What I have is a sheet that users access to pull up customer information
from another sheet. This code is attached to a form with a ComboBox
(ComboBox1) and 3 TextBoxes (1,2,3) that will eventually allow the users to
locate and change customer info. This code locates and fills in the
TextBoxes' information based upon the record displayed in The ComboBox. I can
change the information in the TextBoxes, but the new info added right now
only changes for TextBox1. Once I place the focus back onto ComboBox1, the
information reverts back to what was originally there. Now that I've confused
everyone, here's the code. TextBoxes 2 & 3 are not updating the sheet with
the new info. Any Thoughts?

Private Sub ComboBox1_Change()

Dim res As Variant
Set ws1 = Worksheets("Customer Database")
ws1.Activate
With ws1
res = Application.Match(ComboBox1.Value, Range("A:A"), 0)
If IsError(res) Then
MsgBox ComboBox1.Value & " Not Found"
Else
For i = 1 To 3
Me.Controls("TextBox" & i) = .Cells(res, i + 1)
Next i
End If
End With
End Sub

Private Sub CommandButton1_Click()

Dim res As Variant
Set ws1 = Worksheets("Customer Database")
ws1.Activate
With ws1
res = Application.Match(ComboBox1.Value, Range("A:A"), 0)
If IsError(res) Then
MsgBox ComboBox1.Value & " Not Found"
Else
For i = 1 To 3
If Me.Controls("TextBox" & i) < "" Then .Cells(res, i + 1) =
Me.Controls("TextBox" & i).Value
Next i
End If
End With
End Sub

Any help would be appreciated! Thanks!!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Code Review

Eric,
I tried the code and it worked OK. Check the "i" in the code is
not a 1 although your posted is correct so this unlikely.

if you want post your spreadsheet to me )

"Eric" wrote:

Hello all, I got some fantastic help on this problem yesterday and wanted to
see if someone could take a look at my code and possibly offer some
suggestions.

What I have is a sheet that users access to pull up customer information
from another sheet. This code is attached to a form with a ComboBox
(ComboBox1) and 3 TextBoxes (1,2,3) that will eventually allow the users to
locate and change customer info. This code locates and fills in the
TextBoxes' information based upon the record displayed in The ComboBox. I can
change the information in the TextBoxes, but the new info added right now
only changes for TextBox1. Once I place the focus back onto ComboBox1, the
information reverts back to what was originally there. Now that I've confused
everyone, here's the code. TextBoxes 2 & 3 are not updating the sheet with
the new info. Any Thoughts?

Private Sub ComboBox1_Change()

Dim res As Variant
Set ws1 = Worksheets("Customer Database")
ws1.Activate
With ws1
res = Application.Match(ComboBox1.Value, Range("A:A"), 0)
If IsError(res) Then
MsgBox ComboBox1.Value & " Not Found"
Else
For i = 1 To 3
Me.Controls("TextBox" & i) = .Cells(res, i + 1)
Next i
End If
End With
End Sub

Private Sub CommandButton1_Click()

Dim res As Variant
Set ws1 = Worksheets("Customer Database")
ws1.Activate
With ws1
res = Application.Match(ComboBox1.Value, Range("A:A"), 0)
If IsError(res) Then
MsgBox ComboBox1.Value & " Not Found"
Else
For i = 1 To 3
If Me.Controls("TextBox" & i) < "" Then .Cells(res, i + 1) =
Me.Controls("TextBox" & i).Value
Next i
End If
End With
End Sub

Any help would be appreciated! Thanks!!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,670
Default Code Review

Well, I checked the code and indeed the "i"s are "i"s. Something interesting
I found out. If I blank out the TextBoxes and only update one TextBox at a
time, this code as it is written works. The problem is, I'd like to be able
to make the code fill all 3 fields based upon info in the TextBoxes with one
click of a button. Not one at a time.

Any suggestions?

"Toppers" wrote:

Eric,
I tried the code and it worked OK. Check the "i" in the code is
not a 1 although your posted is correct so this unlikely.

if you want post your spreadsheet to me )

"Eric" wrote:

Hello all, I got some fantastic help on this problem yesterday and wanted to
see if someone could take a look at my code and possibly offer some
suggestions.

What I have is a sheet that users access to pull up customer information
from another sheet. This code is attached to a form with a ComboBox
(ComboBox1) and 3 TextBoxes (1,2,3) that will eventually allow the users to
locate and change customer info. This code locates and fills in the
TextBoxes' information based upon the record displayed in The ComboBox. I can
change the information in the TextBoxes, but the new info added right now
only changes for TextBox1. Once I place the focus back onto ComboBox1, the
information reverts back to what was originally there. Now that I've confused
everyone, here's the code. TextBoxes 2 & 3 are not updating the sheet with
the new info. Any Thoughts?

Private Sub ComboBox1_Change()

Dim res As Variant
Set ws1 = Worksheets("Customer Database")
ws1.Activate
With ws1
res = Application.Match(ComboBox1.Value, Range("A:A"), 0)
If IsError(res) Then
MsgBox ComboBox1.Value & " Not Found"
Else
For i = 1 To 3
Me.Controls("TextBox" & i) = .Cells(res, i + 1)
Next i
End If
End With
End Sub

Private Sub CommandButton1_Click()

Dim res As Variant
Set ws1 = Worksheets("Customer Database")
ws1.Activate
With ws1
res = Application.Match(ComboBox1.Value, Range("A:A"), 0)
If IsError(res) Then
MsgBox ComboBox1.Value & " Not Found"
Else
For i = 1 To 3
If Me.Controls("TextBox" & i) < "" Then .Cells(res, i + 1) =
Me.Controls("TextBox" & i).Value
Next i
End If
End With
End Sub

Any help would be appreciated! Thanks!!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Code Review

Eric,
I changed all textboxes at once and it worked; I changed one
textbox and it worked. There is no need to blank out the textboxes - just
change the one(s) as required and leave the other(s) unchanged. Post your
book to me at address in previous posting , with some test data and I'll look
at this weekend.

"Eric" wrote:

Well, I checked the code and indeed the "i"s are "i"s. Something interesting
I found out. If I blank out the TextBoxes and only update one TextBox at a
time, this code as it is written works. The problem is, I'd like to be able
to make the code fill all 3 fields based upon info in the TextBoxes with one
click of a button. Not one at a time.

Any suggestions?

"Toppers" wrote:

Eric,
I tried the code and it worked OK. Check the "i" in the code is
not a 1 although your posted is correct so this unlikely.

if you want post your spreadsheet to me )

"Eric" wrote:

Hello all, I got some fantastic help on this problem yesterday and wanted to
see if someone could take a look at my code and possibly offer some
suggestions.

What I have is a sheet that users access to pull up customer information
from another sheet. This code is attached to a form with a ComboBox
(ComboBox1) and 3 TextBoxes (1,2,3) that will eventually allow the users to
locate and change customer info. This code locates and fills in the
TextBoxes' information based upon the record displayed in The ComboBox. I can
change the information in the TextBoxes, but the new info added right now
only changes for TextBox1. Once I place the focus back onto ComboBox1, the
information reverts back to what was originally there. Now that I've confused
everyone, here's the code. TextBoxes 2 & 3 are not updating the sheet with
the new info. Any Thoughts?

Private Sub ComboBox1_Change()

Dim res As Variant
Set ws1 = Worksheets("Customer Database")
ws1.Activate
With ws1
res = Application.Match(ComboBox1.Value, Range("A:A"), 0)
If IsError(res) Then
MsgBox ComboBox1.Value & " Not Found"
Else
For i = 1 To 3
Me.Controls("TextBox" & i) = .Cells(res, i + 1)
Next i
End If
End With
End Sub

Private Sub CommandButton1_Click()

Dim res As Variant
Set ws1 = Worksheets("Customer Database")
ws1.Activate
With ws1
res = Application.Match(ComboBox1.Value, Range("A:A"), 0)
If IsError(res) Then
MsgBox ComboBox1.Value & " Not Found"
Else
For i = 1 To 3
If Me.Controls("TextBox" & i) < "" Then .Cells(res, i + 1) =
Me.Controls("TextBox" & i).Value
Next i
End If
End With
End Sub

Any help would be appreciated! Thanks!!

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Months of review Pasty Excel Worksheet Functions 7 November 13th 06 05:17 PM
vba code to block review toolbar Todd F Excel Programming 7 October 16th 06 12:23 AM
Change the interior color of a cell - Code Review Tiny Tim Excel Programming 6 December 17th 05 09:49 PM
code that might be causing error - please review and comment bruce forster Excel Programming 4 May 21st 04 03:06 AM
VB6 with Excel Objects: Please review my code Kurt Remlin Excel Programming 6 May 1st 04 03:36 AM


All times are GMT +1. The time now is 03:12 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"