Solved

Change size of text fields on a form dynamically.

Posted on 2002-05-03
3
139 Views
Last Modified: 2010-05-02
I'm using VB6 against an sql server 7 database.
I have a form with a datagrid on it;
when the user double-clicks on a certain record in the grid, it should bring up that record on another form in edit mode.
The edit form is working now.
---------------------------
However, I'm trying to add code where I can resize the input text fields based on the form that is brought up.
I have to do this because when I insert into the database, some fields are only 2 characters in length while some are 3 characters in length.
This throws my grid off for some reason.
Now when the user double-clicks on a record the record that is editable is the previous record that the user clicked on.
-----------
I do this thru a big select case statement and for some reason, this throws off the grid.
I do this in the form_activate routine but is there somewhere else I could put this code?
I tried it in the form_initialize event but that didn't work either.
Here's a code sample where I try to set the form properties:
Is there an alternative method to do what I want to do?
---------------------------------

Private Sub Form_Activate()
'setup form properties here

    Select Case CurrentForm
   
        Case "AppropBills"
            frmMaint.Caption = "Approp Bills " & CurrentYear
            txtFormName = "Approp Bills " & CurrentYear
            cmdInquirybyCode.Caption = "List Approp Bills by &Code"
            cmdInquirybySequence.Caption = "List Approp Bills by &Sequence"
            tblMaint = "AppropBills"
            frmMaintEdit.txtDescription.MaxLength = 80
            frmMaintEdit.txtCode.MaxLength = 3
           
        Case "FundTypes"
0
Comment
Question by:jtrapat1
3 Comments
 
LVL 18

Expert Comment

by:bobbit31
ID: 6989078
if i understand you correctly:

1) user dbl clicks on a row in datagrid
2) opens a new form
3) you set text field maxlengths

what do you mean this throws off your grid?
0
 

Author Comment

by:jtrapat1
ID: 6989289
I'll try to explain this better.
The grid is working fine now.
When I add in the code to change the maxlength property of the text fields here's what happens:
I double-click on a particular record but the record that is brought up is blank.
Then, I double-click again and the record that is brought up is the previous record that I clicked on.
So, it's like the grid is always one behind the record that I select.
The DataGrid isn't the Microsoft one; it's a third party control from Sheridan but works the same.
I thought it may have to do with how the grid is initialized but it's in a user control.
I don't see why the other properties can be changed on the fly but there's something it doesn't like about the maxlength property for text fields.


Thanks
0
 
LVL 2

Accepted Solution

by:
ventond earned 100 total points
ID: 6989452
I suspect your code does something like:

sub grid_dblClick
frmMaintEdit.show
frmMaintedit.currentform="ApproBills"
end sub

vb does this:
Load frmMaintedit
frmMaintEdit_Load
Show frmMaintEdit
frmMaintEdit_Activate
frmmaintedit.currentform="ApproBills"

What you want vb to do is:
Load frmMaintedit
frmMaintEdit_Load
frmmaintedit.currentform="ApproBills" <---change
Show frmMaintEdit
frmMaintEdit_Activate

You need to change your code to:
Load frmMaintEdit
frmMaintedit.currentform="ApproBills"
frmMaintEdit.Show

This is a very common error. You can see the sequence if you single step through the code.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

706 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

20 Experts available now in Live!

Get 1:1 Help Now