Solved

Change size of text fields on a form dynamically.

Posted on 2002-05-03
3
149 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
vba find the last empty column 10 88
using web browser with BING 40 110
How to measure sizes and angles in scanned images ? 3 52
Problem to With line 4 39
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

912 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

21 Experts available now in Live!

Get 1:1 Help Now